CF416B:Art Union(dp)
来源:互联网 发布:软件分享论坛 app 编辑:程序博客网 时间:2024/05/23 22:18
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.
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.
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.
5 112345
1 3 6 10 15
4 22 53 15 310 1
7 8 13 21
# include <stdio.h># include <string.h># include <algorithm>using namespace std;int main(){ int m, n, dp[50001][6]; while(~scanf("%d%d",&m,&n)) { memset(dp, 0, sizeof(dp)); for(int i=1; i<=m; ++i) for(int j=1; j<=n; ++j) scanf("%d",&dp[i][j]); for(int i=1; i<=m; ++i) for(int j=1; j<=n; ++j) dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + dp[i][j]; for(int i=1; i<m; ++i) printf("%d ",dp[i][n]); printf("%d\n",dp[m][n]); } return 0;}
- CF416B:Art Union(dp)
- 416B - Art Union (DP)
- CodeForces 416B-A - Art Union-DP
- Codeforces 416B Art Union(贪心)
- cfB - Art Union
- codeforces 416 B. Art Union
- codeforces 416 B. Art Union
- CF--416B Art Union
- CodeForces 416B Art Union
- codeforces 416B Art Union
- 省赛组队赛 - G题 Art Union
- ART
- ART
- Adaptive Resonance Theory(ART)
- 【常识】ART(Android runtime)
- union和union All的区别(union联合)
- hive union (all)
- 联合体(union)
- Web请求过程总结
- 欢迎使用CSDN-markdown编辑器
- Maven安装Jar包到本地仓库
- Qt-俄罗斯方块
- Android开发,仿钉钉审核列表功能实现
- CF416B:Art Union(dp)
- 开发微信公众号网页用到的一些工具记录
- jquery attr()方法
- 启动工程时web.xml加载顺序
- 僵尸对象导致crash(Thread 1:EXC_BAD_ACCESS(code=EXC_I386_GPFLT))
- github之微信签到小程序开坑系列一:开坑
- Retrofit2.0使用总结及注意事项
- 十大著名思想实验
- Ubuntu美化Mac教程