zoukankan      html  css  js  c++  java
  • Codeforces Round #241 (Div. 2)->B. Art Union

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

    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个画家,后一个画家要在前一个画家花了当前那幅画所需部分之后才能画,求每一幅画n个画家画完后所需的时间。
    思路:先用b[i][j]存入所输入的数据,然后遍历每一列(第i个画家画完所有画所需时间),用dp[j]存第j幅画完成所需时间。
    dp[j]等于前面用的最大时间加上当前他需要的时间。
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main() {
     4     int n,m;
     5     cin>>n>>m;
     6     int b[n][m];
     7     for(int i=0; i<n; i++) {
     8         for(int j=0; j<m; j++) {
     9             cin>>b[i][j];
    10         }
    11     }
    12     vector<int> dp(n);
    13     for(int i=0;i<m;i++){
    14         int free=0;
    15         for(int j=0;j<n;j++){
    16             int start=max(free,dp[j]);
    17             dp[j]=start+b[j][i];
    18             free=dp[j];
    19         }
    20     }
    21     for(int i=0; i<n; i++)
    22         printf("%d%c",dp[i],i==n-1?'
    ':' ');
    23     return 0;
    24 }
    
    
    
    
    
    
  • 相关阅读:
    docker compose 笔记
    一个简单的计划
    译Node.js应用的持续部署
    Javascript中的字典和散列
    施耐德保护调试技巧
    施耐德Sepam 40系列备自投逻辑
    请随时告诉自己
    顺其自然
    启用
    我们能做的是......
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/5683062.html
Copyright © 2011-2022 走看看