RMRC2016 G:Flow Shop (DP)
Flow Shop
时间限制: 6 Sec 内存限制: 128 MB提交: 16 解决: 15
[提交][状态][讨论版]
题目描述
harvest grain). All swathers go through the same basic stages in their construction: for example they all need to have a cutting bar, a grain belt, and a reel fitted. However, these components can be customized based on the buyer’s
needs, so these various stages may take different amounts of time between different swathers.
N swathers have been ordered and there are M stages in the manufacturing process. The swathers will each go through the same sequence of stages.
In particular, the processing occurs as follows: For each swather i and each stage j, it takes Pij units of time to complete stage j for swather i. The workers at each stage may only work on one swather at a time. At the start of the day all swather orders are ready to be processed by the first stage. At any point in the process, if the workers at stage j are idle and there are swathers waiting to be processed at this stage then the workers will pick the swather that has the lowest label (they are labelled from 1 to N). Note that the work on a stage j can only be started after the work on the stage j-1 is completed.
Determine the time each swather is completed.
N swathers have been ordered and there are M stages in the manufacturing process. The swathers will each go through the same sequence of stages.
In particular, the processing occurs as follows: For each swather i and each stage j, it takes Pij units of time to complete stage j for swather i. The workers at each stage may only work on one swather at a time. At the start of the day all swather orders are ready to be processed by the first stage. At any point in the process, if the workers at stage j are idle and there are swathers waiting to be processed at this stage then the workers will pick the swather that has the lowest label (they are labelled from 1 to N). Note that the work on a stage j can only be started after the work on the stage j-1 is completed.
Determine the time each swather is completed.
输入
There is only one test case in each file. It begins with a single line containing N andM (1≤N,M≤1000),the number of swathers and stages (respectively). Following this are N lines, each withM integers. The j'th integer of the i’th
line is Pij , giving the amount of time it will take for the workers at stage j to complete swather i (1≤Pij≤106).
输出
Output a single line containing N integers T1 T2...Tn with a single space between consecutive integers.
These should be such that stage M for swather i is completed at time Ti.
These should be such that stage M for swather i is completed at time Ti.
样例输入
2 3
1 2 3
3 2 1
样例输出
6 7
这道题 是严格按照 顺序 来的 所以说 也不能算是 dp
如果 按照dp 讲的 话 枚举列 对于 每行 判断 dp[j] 与 dp[j-1] 的 关系
#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <queue> #include <stack> #include <stdlib.h> #include <list> #include <map> #include <set> #include <bitset> #include <vector> #define mem(a,b) memset(a,b,sizeof(a)) #define findx(x) lower_bound(b+1,b+1+bn,x)-b #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) #define S1(n) scanf("%d",&n) #define SL1(n) scanf("%I64d",&n) #define S2(n,m) scanf("%d%d",&n,&m) #define SL2(n,m) scanf("%I64d%I64d",&n,&m) #define Pr(n) printf("%d\n",n) using namespace std; typedef long long ll; const double PI=acos(-1); const int INF=0x3f3f3f3f; const double esp=1e-6; const int maxn=1e6+5; const int MOD=1e9+7; const int mod=1e9+7; int dir[5][2]={0,1,0,-1,1,0,-1,0}; int maps[1100][1100]; int dp[1200]; int main() { int n,m; while(~S2(n,m)) { mem(maps,0); mem(dp,0); int sum=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) S1(maps[i][j]); int ans=0; for(int i=1;i<=n;i++) dp[i]+=maps[i][1]; for(int i=2;i<=m;i++)//列 for(int j=1;j<=n;j++)// 行 { if(j==1) dp[j]+=maps[j][i]; else { if(dp[j]>dp[j-1]) dp[j]+=maps[j][i]; else dp[j]=dp[j-1]+maps[j][i]; } } for(int i=1;i<=n;i++) { if(i==1) printf("%d",dp[i]); else printf(" %d",dp[i]); } cout<<endl; } return 0; }
123
岂曰无衣?与子同袍。王于兴师,修我戈矛。与子同仇!
岂曰无衣?与子同泽。王于兴师,修我矛戟。与子偕作!
岂曰无衣?与子同裳。王于兴师,修我甲兵。与子偕行!