zoukankan      html  css  js  c++  java
  • n个人作m幅画

    题目网址: http://codeforces.com/problemset/problem/416/B

    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 tijis 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.

    Sample test(s)
    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 

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    const int N=50005;
    int a[N][5];
    int dp[N][5];
    
    int main()
    {
        int m,n,sum;
        while(scanf("%d%d",&m,&n)!=EOF)
        {
            for(int i=1;i<=m;i++)
            for(int j=1;j<=n;j++)
            cin>>a[i][j];
            memset(dp,0,sizeof(dp));
            sum=0;
            for(int i=1;i<=n;i++)
            {
                sum+=a[1][i];
                dp[1][i]=sum;
            }
            sum=0;
            for(int i=1;i<=m;i++)
            {
                sum+=a[i][1];
                dp[i][1]=sum;
            }
            for(int i=2;i<=m;i++)
            for(int j=2;j<=n;j++)
            dp[i][j]=max(dp[i][j-1],dp[i-1][j])+a[i][j];
            for(int i=1;i<m;i++)
            printf("%d ",dp[i][n]);
            printf("%d
    ",dp[m][n]);
        }
        return 0;
    }
  • 相关阅读:
    HBase数据存储格式
    百元买百鸡
    驾驶机动车在高速公路上倒车、逆行、穿越中央分隔带掉头的一次记6分。
    驾驶机动车在高速公路遇到能见度低于200米的气象条件时,最高车速是多少?_2600218
    驾驶人违反交通运输管理法规发生重大事故后,因逃逸致人死亡的,处3年以上7年以下有期徒刑。
    国家级心理咨询师培训(二、三级)_课程开设_北京林业大学在职课程进修班(同等学历)网站
    三级心理咨询师_百度百科
    国家二级心理咨询师_百度百科
    国家二级心理咨询师
    国家二级心理咨询师
  • 原文地址:https://www.cnblogs.com/chen9510/p/5022169.html
Copyright © 2011-2022 走看看