Codeforces Round #241 (Div. 2) B. Art Union 基础dp
2016-07-02 17:19
330 查看
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
output
input
output
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 思路:dp[i][t]=max(dp[i][t-1],dp[i-1][t])+a[i][t];
#include<bits/stdc++.h> using namespace std; #define ll __int64 #define mod 1000000007 #define esp 0.00000000001 const int N=5e4+10,M=1e6+10,inf=1e9; int dp [10]; int a [10]; int main() { int x,y,z,i,t; scanf("%d%d",&x,&y); for(i=1;i<=x;i++) for(t=1;t<=y;t++) scanf("%d",&a[i][t]); for(i=1;i<=x;i++) { for(t=1;t<=y;t++) dp[i][t]=max(dp[i][t-1],dp[i-1][t])+a[i][t]; } for(i=1;i<=x;i++) cout<<dp[i][y]<<" "; return 0; }
相关文章推荐
- Sping与hibernate和Struts的整合及使用
- [Hibernate 2]session的三种状态
- 《深入理解Nginx》阅读与实践 使用upstream和subrequest访问第三方服务 no port in upstream
- [Hibernate 2]session的三种状态
- Tair源码阅读1---ConfigServer
- objective-C程序设计学习笔记3--分类和协议
- springMVC的拦截器工作流程
- 【笔记】PMBOK第一章绪论
- Java-类库-Guava-Preconditions检验参数
- 16.4
- qt 波形图
- Vue.js——60分钟快速入门
- servlet、jsp跳转(传值)总结及URL传参数
- 折腾 Phalcon 的笔记
- C#:Socket通信
- block没那么难 block和变量的内存管理(二)
- SQL Server - 小鸟系列之T-SQL基础篇
- linux 安装 python2.7 +配置mysql
- 最长回文子串
- 付款前.检查状态.防止重复付款,需要ajax设置为同步,等待ajax返回结果再使用