Aragorn's Story

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/problemset/problem/148/E

Description

Our protagonist is the
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

The first line of input data contains two integers n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 10000). The next n lines contain the values of the items on the shelves: the first number gives the number of items on this shelf (an integer between 1 and 100, inclusive), followed by the values of the items (integers between 1 and 100, inclusive), in the order in which they appear on the shelf (the first number corresponds to the leftmost item, the last one — to the rightmost one). The total number of items is guaranteed to be at least m.

Output

Output the maximal total value of a tantrum of m shrieks.

Sample Input

2 3
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的更多相关文章

  1. Codeforces 730J:Bottles(背包dp)

    http://codeforces.com/problemset/problem/730/J 题意:有n个瓶子,每个瓶子有一个当前里面的水量,还有一个瓶子容量,问要把所有的当前水量放到尽量少的瓶子里至 ...

  2. Codeforces 922 E Birds (背包dp)被define坑了的一题

    网页链接:点击打开链接 Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp ne ...

  3. Codeforces 922 思维贪心 变种背包DP 质因数质数结论

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  4. 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/ ...

  5. Codeforces 864E Fire(背包DP)

    背包DP,决策的时候记一下 jc[i][j]=1 表示第i个物品容量为j的时候要选,输出方案的时候倒推就好了 #include<iostream> #include<cstdlib& ...

  6. 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 \( ...

  7. 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 如果只是单纯模拟肯定会超时 ...

  8. 背包dp整理

    01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...

  9. hdu 5534 Partial Tree 背包DP

    Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

随机推荐

  1. java类中访问属性

    package first; public class for_protect { private int age=10; int number = 100; public void show(){ ...

  2. python之微信公众号开发(基本配置和校验)

    前言 最近有微信公众号开发的业务,以前没有用python做过微信公众号开发,记录一下自己的学习和开发历程,共勉! 公众号类型 订阅号 普通订阅号 认证订阅号 服务号 普通服务号 认证服务号 服务方式 ...

  3. WebHeaderCollection类

    .net添加http报头 string[] allKeys = WebHeaderCollection.AllKeys; for (int i = 0; i < allKeys.Length; ...

  4. 未找到与约束 ContractName Microsoft.VisualStudio.Utilitues.IContentTypeRegistryService......

    1.问题提出 用VS 2013 with Update5 开发项目,点击项目中的文件,发现打不开,抛出如下的错误. 错误提示: 未找到与约束 ContractName Microsoft.Visual ...

  5. Sklearn-GridSearchCV网格搜索

    GridSearchCV,它存在的意义就是自动调参,只要把参数输进去,就能给出最优化的结果和参数.但是这个方法适合于小数据集,一旦数据的量级上去了,很难得出结果.这个时候就是需要动脑筋了.数据量比较大 ...

  6. The hub and spoke model 轮辐模型/辐射模型

    最近一些文档中提到The Hub and Spoke Model,这里mark一下.hub表示轮毂,spoke表示轮辐,轮辐模型是简化网络路由的一套中心化的体系,广泛应用于航空.货运.快递以及网络技术 ...

  7. CGIC简明教程(转摘)

    CGIC简明教程 本系列的目的是演示如何使用C语言的CGI库“CGIC”完成Web开发的各种要求. *********************************     基础知识       1 ...

  8. linux下设置opencv环境变量

    一.安装opencv(这里不再讲述) 二.添加库路径(创建opencv.conf文件) 输入命令:vi /etc/ld.so.conf.d/opencv.conf 输入/usr/local/lib,并 ...

  9. Asp.net vNext 学习之路(二)

    View component(视图组件)应该是MVC6 新加的一个东西,类似于分部视图.本文将演示在mvc 6中 怎么添加视图组件以及怎么在视图中注入一个服务. 本文包括以下内容: 1,创建一个新的a ...

  10. Codeforces Round #302 (Div. 1) D - Road Improvement 树形dp

    D - Road Improvemen 思路:0没有逆元!!!! 不能直接除,要求前缀积和后缀积!!! #include<bits/stdc++.h> #define LL long lo ...