Codeforces Round #241 (Div. 2) B dp
1 second
256 megabytes
standard input
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.
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.
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.
5 1
1
2
3
4
5
1 3 6 10 15
4 2
2 5
3 1
5 3
10 1
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的更多相关文章
- 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 ...
- Codeforces Round #241 (Div. 2) B. Art Union (DP)
题意:有\(n\)个画家,\(m\)幅画,每个画家负责\(m\)幅画,只有前一个画家画完时,后面一个画家才能接着画,一个画家画完某幅画的任务后,可以开始画下一幅画的任务,问每幅画最后一个任务完成时的时 ...
- 严格递增类的dp Codeforces Round #371 (Div. 1) C dp
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...
- 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...
- Codeforces Round #548 (Div. 2) C dp or 排列组合
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...
- Codeforces Round #536 (Div. 2) E dp + set
https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希
https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...
- Codeforces Round #303 (Div. 2) C dp 贪心
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- 转:Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
转自:http://blog.csdn.net/business122/article/details/7536991 创建列表 sample_list = ['a',1,('a','b')] Pyt ...
- 学习笔记 | java反序列化漏洞分析
java反序列化漏洞是与java相关的漏洞中最常见的一种,也是网络安全工作者关注的重点.在cve中搜索关键字serialized共有174条记录,其中83条与java有关:搜索deserialized ...
- 谭浩强 c++程序设计第一章课后习题 第7题
#include <iostream> using namespace std; int main() { int a,b,c; int f(int x,int y,int z);//这是 ...
- ios 导航视图控制器 跳转
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...
- 32-3题:LeetCode103. Binary Tree Zigzag Level Order Traversal锯齿形层次遍历/之字形打印二叉树
题目 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 ...
- (83)zabbix Less than 25% free in the configuration cache解决
在zabbix server默认配置下,出现告警:Less than 25% free in the configuration cache,字面意思是:可用的配置缓存少于25%. 报错如下图: 增加 ...
- nginx反向代理后端web服务器记录客户端ip地址
nginx在做反向代理的时候,后端的nginx web服务器log中记录的地址都是反向代理服务器的地址,无法查看客户端访问的真实ip. 在反向代理服务器的nginx.conf配置文件中进行配置. lo ...
- 5- vue django restful framework 打造生鲜超市 -完成商品列表页(上)
使用Python3.6与Django2.0.2(Django-rest-framework)以及前端vue开发的前后端分离的商城网站 项目支持支付宝支付(暂不支持微信支付),支持手机短信验证码注册, ...
- 项目10.2-企业级自动化运维工具---puppet详解
1.认识puppet 1.1 引入 puppet是什么,咱们先不用专业的名词解释它,咱们先描述一些工作场景,看明白这些工作场景,自然会知道puppet是什么. (1)场景一: 管理员想要在100台服务 ...
- hprose 1.0(rpc 框架) - 执行时序图