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、題目:
B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputA 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.
InputThe 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.
OutputPrint 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.
Sample test(s) Input5 1 1 2 3 4 5Output
1 3 6 10 15Input
4 2 2 5 3 1 5 3 10 1Output
7 8 13 21
5、AC代碼:
#include#include #include using namespace std; #define M 100005 int 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