• Codeforces Round #241 (Div. 2) B dp


    B. Art Union
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows.

    Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these n colors. Adding the j-th color to the i-th picture takes the j-th painter tij units of time.

    Order is important everywhere, so the painters' work is ordered by the following rules:

    • Each picture is first painted by the first painter, then by the second one, and so on. That is, after the j-th painter finishes working on the picture, it must go to the (j + 1)-th painter (if j < n);
    • each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on;
    • each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest;
    • as soon as the j-th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter.

    Given that the painters start working at time 0, find for each picture the time when it is ready for sale.

    Input

    The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to work on the i-th picture.

    Output

    Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture.

    Examples
    Input
    5 1
    1
    2
    3
    4
    5
    Output
    1 3 6 10 15 
    Input
    4 2
    2 5
    3 1
    5 3
    10 1
    Output
    7 8 13 21 

    题意: n幅 m个画家 每个画家按照次序画 给出每个画家画每幅画的时间
    对于同一幅画 画家s画完 画家s+1才能画
    画家只能同一时间段画一幅画 当结束当前画后 就可以进行下幅画 或 等待下一幅画被前一个画家画完才能画
    问每一幅画被最后一个画家画完的时刻

    题解: 动态规划处理 dp[i][j] 表示 第j个画家画完第i幅画的时刻
    mp[i][j]代表 第j个画家画完第i幅画所需要的时间
    转移方程 :
    dp[i][j]=max(dp[i][j-1],dp[i-1][j])+mp[i][j]

     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<cstdio>
     5 #include<queue>
     6 #define ll long long
     7 #define mod 1e9+7
     8 #define PI acos(-1.0)
     9 #define bug(x) printf("%%%%%%%%%%%%%",x);
    10 #define inf 1e8
    11 using namespace std;
    12 int n,m;
    13 int mp[50005][6];
    14 int time[50005][6];
    15 int main()
    16 {
    17     scanf("%d %d",&n,&m);
    18     for(int i=1;i<=n;i++)
    19     {
    20         for(int j=1;j<=m;j++)
    21         scanf("%d",&mp[i][j]);
    22     }
    23     memset(time,0,sizeof(time));
    24     time[1][1]=mp[1][1];
    25     for(int j=2;j<=m;j++)
    26     time[1][j]=time[1][j-1]+mp[1][j];
    27     for(int j=2;j<=n;j++)
    28     time[j][1]=time[j-1][1]+mp[j][1];
    29     for(int j=2;j<=m;j++)
    30     for(int i=2;i<=n;i++)
    31     {
    32         for(int j=2;j<=m;j++)
    33         {
    34             if(time[i-1][j]>time[i][j-1])
    35                 time[i][j]=time[i-1][j]+mp[i][j];
    36             else
    37                 time[i][j]=time[i][j-1]+mp[i][j];
    38         }
    39     }
    40     printf("%d",time[1][m]);
    41     for(int i=2;i<=n;i++)
    42         printf(" %d",time[i][m]);
    43     printf("
    ");
    44     return 0;
    45 }
  • 相关阅读:
    Boa移植到Android——ztg
    How to port lighttpd to Android
    android 4.4源码下载——百度云盘地址
    CentOS7——解压7z文件——p7zip
    android—mm—mmm—没有规则可以创建target/product/generic/obj/SHARED_LIBRARIES
    日常美食 小纪
    日常美食 小纪
    上海植物园
    上海之行(一)田子坊
    上海之行(一)田子坊
  • 原文地址:https://www.cnblogs.com/hsd-/p/5676788.html
Copyright © 2020-2023  润新知