题意:一群匪徒要进入一个酒店。酒店的门有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的更多相关文章

  1. poj - 1159 - Palindrome(滚动数组dp)

    题意:一个长为N的字符串( 3 <= N <= 5000).问最少插入多少个字符使其变成回文串. 题目链接:http://poj.org/problem?id=1159 -->> ...

  2. Palindrome_滚动数组&&DP

    Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...

  3. HDU 4576 简单概率 + 滚动数组DP(大坑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 坑大发了,居然加 % 也会超时: #include <cstdio> #includ ...

  4. Making the Grade_滚动数组&&dp

    Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...

  5. Gym 100507G The Debut Album (滚动数组dp)

    The Debut Album 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/G Description Pop-group & ...

  6. hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)

    题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...

  7. POJ 3666 Making the Grade (DP滚动数组)

    题意:农夫约翰想修一条尽量平缓的路,路的每一段海拔是A[i],修理后是B[i],花费|A[i] – B[i]|,求最小花费.(数据有问题,代码只是单调递增的情况) #include <stdio ...

  8. POJ 1159 Palindrome(区间DP/最长公共子序列+滚动数组)

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 56150   Accepted: 19398 Desc ...

  9. poj 2663 Tri Tiling (状压dp+多米诺骨牌问题+滚动数组反思)

    本来直接一波状压dpAC的 #include<cstdio> #include<cstring> #include<algorithm> #define REP(i ...

随机推荐

  1. POJ 3268 Silver Cow Party(dij+邻接矩阵)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<algorithm> #include<cs ...

  2. jquery之全选全不选

    <input type="checkbox" onclick="selall(this)" />全选/全不选 <input type=&quo ...

  3. git上传代码到github

    git上传代码到github [root@bigdata-hadoop- ~]# git init [root@bigdata-hadoop- ~]# git add zeppelin [root@b ...

  4. Excel教程(12) - 数学和三角函数

    ABS     用途:返回某一参数的绝对值.   语法:ABS(number) 参数:number 是需要计算其绝对值的一个实数. 实例:如果 A1=-16,则公式"=ABS(A1)&quo ...

  5. html5 读写sqlite数据库

    var db = openDatabase('MyData','','My Database',102400); //首先它创建一个数据库表,里面有3个字段 db.transaction(functi ...

  6. PHP 流程

    登录页面 <body> <form action="loginchuli.php" method="post"> <div> ...

  7. 表单提交是ajax提交,PC提交没问题但是手机提交就会一直跳到error,并且也没状态码一直是0

    真是被自己蠢死了button标签他会自动提交刷新页面 <form id="baoming_from"> <p>请填写您的个人信息</p> < ...

  8. HDU--1301--Jungle Roads(最小生成树)

    Problem Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of for ...

  9. Load PE from memory(反取证)(未完)

      Article 1:Loading Win32/64 DLLs "manually" without LoadLibrary() The most important step ...

  10. 100个精选zencart扩展插件

    100个精选zencart扩展插件 特别推荐 1. 数据库备份 2. 产品横向布局. 3. 邮件订阅Newsletter Subscribe. 4. google 翻译google_translate ...