zoukankan      html  css  js  c++  java
  • Art Union

    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
    Copy
    5 1
    1
    2
    3
    4
    5
    output
    Copy
    1 3 6 10 15 
    input
    Copy
    4 2
    2 5
    3 1
    5 3
    10 1
    output
    Copy
    7 8 13 21 



    做题像是憋屎,想明白后,一下就出来了。
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <unordered_set>
    #include <unordered_map>
    #include <xfunctional>
    #define ll long long
    #define mod 998244353
    using namespace std;
    int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
    const int maxn = 16;
    const long long inf = 0x7f7f7f7f7f7f7f7f;
    
    int main()
    {
        int m, n;
        cin >> m >> n;
        vector<vector<int>> t(m+1, vector<int>(n+1,0));
        for (int i = 1; i <= m; i++)
            for (int j = 1; j <= n; j++)
                cin >> t[i][j];
        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (t[i][j - 1] < t[i - 1][j])
                    t[i][j] += t[i - 1][j];
                else
                    t[i][j] += t[i][j - 1];
            }
        }
        for (int i = 1; i <= m; i++)
        {
            cout << t[i][n] << " ";
        }
        return 0;
    }
  • 相关阅读:
    Day5:面向对象的定义(下)
    SQL 查询中not in 与 not exists 的区别
    SQL 语句的执行顺序
    SQL server 连接 查询
    SQL server 约束
    静态类与非静态类,静态成员及使用方法
    HR面试总结
    值类型与引用类型精解
    面试技巧
    MVC与设计模式的关系及MVC的实现原理和设计原理
  • 原文地址:https://www.cnblogs.com/dealer/p/12353106.html
Copyright © 2011-2022 走看看