codeforces 148E Aragorn's Story 背包DP
Aragorn's Story
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://codeforces.com/problemset/problem/148/E
Description
handsome human prince Aragorn comes from The Lord of the Rings. One day
Aragorn finds a lot of enemies who want to invade his kingdom. As
Aragorn knows, the enemy has N camps out of his kingdom and M edges
connect them. It is guaranteed that for any two camps, there is one and
only one path connect them. At first Aragorn know the number of enemies
in every camp. But the enemy is cunning , they will increase or decrease
the number of soldiers in camps. Every time the enemy change the number
of soldiers, they will set two camps C1 and C2. Then, for C1, C2 and
all camps on the path from C1 to C2, they will increase or decrease K
soldiers to these camps. Now Aragorn wants to know the number of
soldiers in some particular camps real-time.
A的某一段完全重合,或者能够经过上下左右平移与折线A的某一段完全重合,则表示秋实大哥吹出了妹子的一部分旋律。
Input
Output
Output the maximal total value of a tantrum of m shrieks.
Sample Input
3 3 7 2
3 4 1 5
Sample Output
15
HINT
题意
有n排花盆,每排有k个,然后有个人想扔m个花瓶,每个花瓶有个价值val
他只能选择每一排的最左边或者最右边扔
求扔的最大价值
题解:
背包问题,bag[i][j]表示第i排扔j个的最大值
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int bag[][];
int t[];
int a[][];
int dp[][];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&t[i]);
for(int j=;j<=t[i];j++)
{
scanf("%d",&a[i][j]);
a[i][j]+=a[i][j-];
}
}
for(int i=;i<=n;i++)
for(int j=;j<=t[i];j++)
for(int k=;k<=j;k++)
bag[i][j]=max(bag[i][j],a[i][k]+a[i][t[i]]-a[i][t[i]-j+k]);
for(int i=;i<=n;i++)
{
for(int j=m;j>=;j--)
{
for(int k=;k<=t[i]&&k<=j;k++)
{
dp[i][j]=max(dp[i][j],dp[i-][j-k]+bag[i][k]);
}
}
}
cout<<dp[n][m]<<endl; }
codeforces 148E Aragorn's Story 背包DP的更多相关文章
- Codeforces 730J:Bottles(背包dp)
http://codeforces.com/problemset/problem/730/J 题意:有n个瓶子,每个瓶子有一个当前里面的水量,还有一个瓶子容量,问要把所有的当前水量放到尽量少的瓶子里至 ...
- Codeforces 922 E Birds (背包dp)被define坑了的一题
网页链接:点击打开链接 Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp ne ...
- Codeforces 922 思维贪心 变种背包DP 质因数质数结论
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...
- Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp
B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...
- Codeforces 864E Fire(背包DP)
背包DP,决策的时候记一下 jc[i][j]=1 表示第i个物品容量为j的时候要选,输出方案的时候倒推就好了 #include<iostream> #include<cstdlib& ...
- Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 背包dp
D. Yet Another Subarray Problem You are given an array \(a_1, a_2, \dots , a_n\) and two integers \( ...
- Codeforces 946 课程表背包DP 数位DFS构造
A B 给你A,B 两个数 1.a=0 OR b=0 break 2.a>=2b a=a-2b 3.b>=2a b=b-2a 如果只是单纯模拟肯定会超时 ...
- 背包dp整理
01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...
- hdu 5534 Partial Tree 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
随机推荐
- 2-Python基础语法-内存管理-运算符-程序控制
目录 1 Python 基础语法 1.1 注释 1.2 缩进 1.3 续行 1.4 标识符 1.5 转义序列 1.6 数字 1.7 字符串 1.8 其他 2 Python 运算符 2.1 赋值运算符 ...
- linux设备驱动模型-浅析-转
1. typeof typeof并非ISO C的关键字,而是gcc对C的一个扩展.typeof是一个关键字(类似sizeof),用于获取一个表达式的类型. 举个简单的例子: char tt; typ ...
- Netty框架入门
一.概述 Netty是由JBOSS提供的一个java开源框架. Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速开发高性能.高可靠性的网络服务器和客户端程序. 二. ...
- hbase学习(二)hbase单机和高可用完全分布式安装部署
hbase版本 2.0.4 与hadoop兼容表http://hbase.apache.org/book.html#hadoop 我的 hadoop版本是3.1 1.单机版hbase 1.1解 ...
- email的传输协议与格式(资源链接)
以下链接为转载. 传输协议: 发:SMTP 收:POP3, IMAP 格式: MIME
- php正则匹配以“abc”开头且不能以“xyz”结尾的字符串
本文介绍下,用php正则区配以"abc"开头的,且不能以"xyz"结尾的字符串的方法,有需要的朋友参考下. 要求:用php正则表达式匹配以“abc”开头,但结尾 ...
- 常用对称加密算法(DES/AES)类(PHP)
看注释,啥也不说了,欢迎各种跨平台测试! /** * 常用对称加密算法类 * 支持密钥:64/128/256 bit(字节长度8/16/32) * 支持算法:DES/AES(根据密钥长度自动匹配使用: ...
- 关于HTML&CSS的笔记
最近在看Jon Duckett的HTML&CSS一书(http://book.douban.com/subject/6585090/),书的排版和讲解方式很不错,并且有许多其他教学材料遗漏的关 ...
- 【ASP.NET MVC】Ajax提交表单
下面这段代码主要有几个特点: 1.Ajax提交表单 2.表单中有一个<input type="file"/> 3.当选择完图片后,利用AJAX提交表单,并在执行成功后返 ...
- 转:asm.js 和 Emscripten 入门教程
转:http://www.ruanyifeng.com/blog/2017/09/asmjs_emscripten.html asm.js 和 Emscripten 入门教程 作者: 阮一峰 日期: ...