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.

输入

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.

样例输入

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值