【滚动数组】 dp poj 1036
题意:一群匪徒要进入一个酒店。酒店的门有k+1个状态,每个匪徒的参数是:进入时间,符合的状态,携带的钱。
酒店的门刚开始状态0,问最多这个酒店能得到的钱数。
思路:
dp数组为DP[T][K].
转移方程dp[i][j]=max(dp[i-1][j],dp[i-1][j-1],dp[i-1][j+1])
因为转移i只跟i-1有关,所以可以用滚动数组dp[2][k].
其实这道题的转移方程很容易想到,只是编程的时候处理边界等细节比较麻烦。还有学习了滚动数组
#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std;
const int N=,K=,T=;
int dp[][K];
struct gang
{
int t,p,s;
}gan[N]; bool cmp(const gang &a,const gang &b)
{
return a.t < b.t;
}
int n,k,t;
bool flag[T];
void solve()
{
for(int i=;i<=n;i++)
flag[gan[i].t]=true;
int w;
sort(gan+,gan+n+,cmp);
for(int i=;i<=t;i++)
{
for(int j=;j<=k && j<=i;j++)
{
w=;
if(flag[i])
{
for(int ii=;ii<=n;ii++)
{
if(gan[ii].t==i && gan[ii].s==j)
w+=gan[ii].p;
}
}
if(j==k)
dp[i%][j]=max(dp[(i-)%][j-],dp[(i-)%][j]);
else if(j==)
dp[i%][j]=max(dp[(i-)%][j+],dp[(i-)%][j]);
else
dp[i%][j]=max(dp[(i-)%][j-],max(dp[(i-)%][j+],dp[(i-)%][j]));
dp[i%][j]+=w;
}
}
int ans=;
for(int j=;j<=k;j++)
{
ans=max(ans,dp[t%][j]);
}
cout << ans << endl;
}
int main()
{
freopen("in.txt","r",stdin);
scanf("%d%d%d",&n,&k,&t);
for(int j=;j<=n;j++)
{
scanf("%d",&gan[j].t);
}
for(int j=;j<=n;j++)
{
scanf("%d",&gan[j].p);
}
for(int j=;j<=n;j++)
{
scanf("%d",&gan[j].s);
}
solve();
return ;
}
【滚动数组】 dp poj 1036的更多相关文章
- poj - 1159 - Palindrome(滚动数组dp)
题意:一个长为N的字符串( 3 <= N <= 5000).问最少插入多少个字符使其变成回文串. 题目链接:http://poj.org/problem?id=1159 -->> ...
- Palindrome_滚动数组&&DP
Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...
- HDU 4576 简单概率 + 滚动数组DP(大坑)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 坑大发了,居然加 % 也会超时: #include <cstdio> #includ ...
- Making the Grade_滚动数组&&dp
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...
- Gym 100507G The Debut Album (滚动数组dp)
The Debut Album 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/G Description Pop-group & ...
- hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)
题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...
- POJ 3666 Making the Grade (DP滚动数组)
题意:农夫约翰想修一条尽量平缓的路,路的每一段海拔是A[i],修理后是B[i],花费|A[i] – B[i]|,求最小花费.(数据有问题,代码只是单调递增的情况) #include <stdio ...
- POJ 1159 Palindrome(区间DP/最长公共子序列+滚动数组)
Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 56150 Accepted: 19398 Desc ...
- poj 2663 Tri Tiling (状压dp+多米诺骨牌问题+滚动数组反思)
本来直接一波状压dpAC的 #include<cstdio> #include<cstring> #include<algorithm> #define REP(i ...
随机推荐
- php基础(三)超全局变量
超全局变量 在 PHP 4.1.0 中引入,是在全部作用域中始终可用的内置变量. PHP 全局变量 - 超全局变量 PHP 中的许多预定义变量都是“超全局的”,这意味着它们在一个脚本的全部作用域中都可 ...
- Memcached 集群的高可用(HA)架构
Memcache自身并没有实现集群功能,如果想用Memcahce实现集群需要借助第三方软件或者自己设计编程实现,这里将采用memagent代理实现,memagent又名magent,大家注意下,不要将 ...
- NOIP2010-普及组复赛模拟试题-第一题-手机
题目背景 Background 现在手机使用越来越广泛了 题目描述 Description 一般的手机的键盘是这样的: 要按出英文字母就必须要按数字键多下.例如要按出 x 就得按 9 两下,第一 ...
- 设计模式4 外观模式 FACADE
一个外观是一个类,其提供的功能介于工具箱的功能和完整系统的功能之间,并为一个包或者一个子系统中的类提供了简化的使用方式.
- 12C dbca silent
dbca needs a template file to create a database. These template can be found in $ORACLE_HOME/assista ...
- 单击Echart饼图实现数据钻取
使用场景和需求: 第一层饼图显示党员党龄分布的情况. 点击某个党龄段,查看拥有该党龄段的党支部. 默认显示3个党支部,余下的党支部合并为其它,点击其它,查看余下的党支部. 点击某个党支部,返回第一层饼 ...
- html5--基础笔记
1.对于<a>标签 以前: <h2><a href="index.html">The home page</a></h2> ...
- 说说final关键字(好像有干货)
在java开发过程中,final是大家常用的关键字,无非就是用来修饰类,方法和变量,来表名类不能被继承,方法不会被覆盖,变量不能被改变,悄悄的说一句,private方法也隐式的final.通过一段时间 ...
- 好玩的获取目录信息的例子[C#]
DirectoryInfo dirinfo = new DirectoryInfo("d:\\111"); DirectoryInfo[] dirs = dirinfo.GetDi ...
- 常用的css
产品鼠标经过加边框效果 .productsCol:hover { box-shadow: 0 0 0 3px #333333 inset; transition: all 0.2s ease 0s; ...