codeforces 416 B. Art Union
来源:互联网 发布:2017年动漫推荐知乎 编辑:程序博客网 时间:2024/04/28 06:06
1、http://codeforces.com/problemset/problem/416/B
2、题目大意:
有m副画,有n个画家,每个画家画完第一幅画之后才可以画第二幅画,每一副画需要n个画家来完成,只有第一个画家完成了,第二个画家才可以开始,求每幅画完成时的最短时间是多少
3、思路
这是一道dp的题目,dp[i][j]表示第i副画第j个画家完成时的最短时间
状态转移方程:
dp[i][j]=max(dp[i][j-1],dp[i-1][j])+a[i][j];
4、题目:
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists ofn 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 thesen colors. Adding the j-th color to the i-th picture takes thej-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 thej-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), wherem is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line containsn integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), wheretij is the time thej-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 then-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
5、AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define M 100005int a[M][15];int dp[M][15];int main(){ int m,n; while(scanf("%d%d",&m,&n)!=EOF) { for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { scanf("%d",&a[i][j]); } } memset(dp,0,sizeof(dp)); int tmp=0; for(int i=1;i<=n;i++) { tmp+=a[1][i]; dp[1][i]=tmp; } tmp=0; for(int i=1;i<=m;i++) { tmp+=a[i][1]; dp[i][1]=tmp; } 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\n",dp[m][n]); } return 0;}
- codeforces 416 B. Art Union
- codeforces 416 B. Art Union
- CodeForces 416B Art Union
- codeforces 416B Art Union
- Codeforces 416B Art Union(贪心)
- CodeForces 416B-A - Art Union-DP
- CF--416B Art Union
- 416B - Art Union (DP)
- Codeforces 560B Gerald is into Art
- CodeForces#313 B. Gerald is into Art
- CodeForces 560B Gerald is into Art
- CodeForces 560B Gerald is into Art
- CodeForces - 560B Gerald is into Art
- cfB - Art Union
- Codeforces 560B Gerald is into Art 放矩形
- Codeforces Round #313 (Div. 2) B. Gerald is into Art
- Codeforces 560B Gerald is into Art(构造性算法)
- Codeforces 560B Gerald is into Art(相片摆放模拟)
- Android中为WindowManager添加的View添加动画
- HDU 1162 Eddy's picture
- android之onCreateOptionsMenu失效,按菜单键无反应
- javascript事件委托技术的原理
- Android解析apk包信息
- codeforces 416 B. Art Union
- Redis常用命令速查 <第二篇>
- 常见几种存储过程分页
- css如何对齐文本框和旁边的图像按钮
- SSL协议与数字证书原理
- 黑马程序员_OC内存管理
- ServiceStack.Redis之IRedisClient<第三篇>
- schema中simpleType元素和complexType元素的区别
- FZU 2105 Digits Count(线段树区间修改)