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= ...
随机推荐
- Java简单爬虫(一)
简单的说,爬虫的意思就是根据url访问请求,然后对返回的数据进行提取,获取对自己有用的信息.然后我们可以将这些有用的信息保存到数据库或者保存到文件中.如果我们手工一个一个访问提取非常慢,所以我们需要编 ...
- php 全文搜索解决方法
全套解决方案 xunsearch 一.安装编译工具 yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-dev ...
- CRM 业务
1. 创建CRM项目 引入插件 创建数据库 from django.db import models from django.db import models class Department(mod ...
- 欧拉回路&欧拉通路判断
欧拉回路:图G,若存在一条路,经过G中每条边有且仅有一次,称这条路为欧拉路,如果存在一条回路经过G每条边有且仅有一次, 称这条回路为欧拉回路.具有欧拉回路的图成为欧拉图. 判断欧拉通路是否存在的方法 ...
- 1、量化投资—为什么选择Python?
Python在量化领域的现状 就跟Java在web领域无可撼动的地位一样,Python也已经在金融量化投资领域占据了重要位置,从各个业务链条都能找到相应的框架实现. 在量化投资(证券和比特币)开源项目 ...
- C#取色器
闲来无事,就写了一个取色器.原理其实很简单,只需要两步, 获取鼠标光标的位置, 获取当前鼠标光标的位置的RGB颜色值. 获取鼠标光标的位置: System.Drawing.Point p = Mous ...
- gtk+学习笔记(三)
gtk感觉函数好多,需要记好多函数,还是多练习,多总结,今天写了一个登陆窗口,很简单,主要是为了加深对这些东西的记忆,直接贴代码 #include<gtk/gtk.h> static Gt ...
- Node.js fs-文件系统
fs.stat,获取文件信息. var fs = require('fs') fs.stat('../index.js', (err, stats) => { if (err) { consol ...
- 几个python one-liner
生成斐波那契数列的前10个数,从1开始.若生成前n个,改为range(n-2).代码很简单: List = reduce(lambda x, y: x + [x[-1] + x[-2]], range ...
- numpy中min函数
numpy提供的数组功能比较常用,NumPy中维数被称为轴,轴数称为秩. import numpy as np 比如a = np.array([[1, 5, 3], [4, 2, 6]]) a.min ...