B. Art Union
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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 tij is the time the j-th painter needs to work on the i-th picture.

Output

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.

Examples
Input
5 1
1
2
3
4
5
Output
1 3 6 10 15 
Input
4 2
2 5
3 1
5 3
10 1
Output
7 8 13 21 

题意: n幅 m个画家 每个画家按照次序画 给出每个画家画每幅画的时间
对于同一幅画 画家s画完 画家s+1才能画
画家只能同一时间段画一幅画 当结束当前画后 就可以进行下幅画 或 等待下一幅画被前一个画家画完才能画
问每一幅画被最后一个画家画完的时刻 题解: 动态规划处理 dp[i][j] 表示 第j个画家画完第i幅画的时刻
mp[i][j]代表 第j个画家画完第i幅画所需要的时间
转移方程 :
dp[i][j]=max(dp[i][j-1],dp[i-1][j])+mp[i][j]
 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#define ll long long
#define mod 1e9+7
#define PI acos(-1.0)
#define bug(x) printf("%%%%%%%%%%%%%",x);
#define inf 1e8
using namespace std;
int n,m;
int mp[][];
int time[][];
int main()
{
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
scanf("%d",&mp[i][j]);
}
memset(time,,sizeof(time));
time[][]=mp[][];
for(int j=;j<=m;j++)
time[][j]=time[][j-]+mp[][j];
for(int j=;j<=n;j++)
time[j][]=time[j-][]+mp[j][];
for(int j=;j<=m;j++)
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(time[i-][j]>time[i][j-])
time[i][j]=time[i-][j]+mp[i][j];
else
time[i][j]=time[i][j-]+mp[i][j];
}
}
printf("%d",time[][m]);
for(int i=;i<=n;i++)
printf(" %d",time[i][m]);
printf("\n");
return ;
}

Codeforces Round #241 (Div. 2) B dp的更多相关文章

  1. Codeforces Round #241 (Div. 2) B. Art Union 基础dp

    B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  2. Codeforces Round #241 (Div. 2) B. Art Union (DP)

    题意:有\(n\)个画家,\(m\)幅画,每个画家负责\(m\)幅画,只有前一个画家画完时,后面一个画家才能接着画,一个画家画完某幅画的任务后,可以开始画下一幅画的任务,问每幅画最后一个任务完成时的时 ...

  3. 严格递增类的dp Codeforces Round #371 (Div. 1) C dp

    http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...

  4. 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp

    http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...

  5. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

  6. Codeforces Round #536 (Div. 2) E dp + set

    https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...

  7. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  8. Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希

    https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...

  9. Codeforces Round #303 (Div. 2) C dp 贪心

    C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 张量 (tensor) 是什么?

    对于大部分已经熟练的数学和物理工作者, 这实在是一个极为基础的问题. 但这个问题在我刚接触张量时也困扰了我很久. 张量的那么多定义, 究竟哪些是对的? (显然都是对的. ) 它们的关系是什么? 我尽可 ...

  2. WinSCP使用与linux命令(小部分命令)

    一.下载一个WinSCP WinSCP是一个Windows环境下使用SSH的开源图形化SFTP客户端.同时支持SCP协议.它的主要功能就是在本地与远程计算机间安全的复制文件..winscp也可以链接其 ...

  3. NSCopying

    ///< .h @interface ChatManager : NSObject <NSCopying> @property (nonatomic) NSUInteger inde ...

  4. linux网络编程之断点传输文件

    以下载链接"http://www.boa.org/boa-0.94.13.tar.gz"为例: 断点续传实验大概步骤: ===================== 1,使用geth ...

  5. java中如何设置HTTP协议的头信息(header)

    首先,我们先看一下http的头信息到底是什么:HTTP(HyperTextTransferProtocol) 即超文本传输协议,目前网页传输的的通用协议.HTTP协议采用了请求/响应模型,浏览器或其他 ...

  6. mysql中如何不重复插入,mysql 重复的不插入,mysql唯一的插入

    INSERT INTO new_schedules_spider_shipsname ( ID,SCAC,VESSEL,VOYAGE,SERVICE_NAME,MD5 ) SELECT NULL,%s ...

  7. 【Ecshop】修改处理用户购物车的行为

    Ecshop v2.7.3的购物车处理方面在现在看来有比较反用户体验的设计: 用户未登录时加入购物车的商品,在用户登录后会被清空而不是加入到登录用户的购物车中: 用户登录后加入购物车的商品,在退出后会 ...

  8. CI框架 重定向redirect()

    CI框架不能使用$this->redirect(),只能使用redirect():并且默认重定向地址带有index.php,如果需要去掉,请使用绝对地址. 使用示例: 通过发送HTTP头,命令客 ...

  9. 日志收集系统Flume及其应用

    Apache Flume概述 Flume 是 Cloudera 提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统.Flume 支持定制各类数据发送方,用于收集各类型数据:同时,Fl ...

  10. [BZOJ1208]宠物收养所(Splay)

    Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物.每个领养者都希望领养到自己满意的宠物,阿Q根据领养者的要求通过他自己发明的一个特 ...