1163 访问艺术馆

题目描述 Description

    皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画。艺术馆的结构,每条走廊要么分叉为二条走廊,要么通向一个展览室。皮尔知道每个展室里藏画的数量,并且他精确地测量了通过每条走廊的时间,由于经验老道,他拿下一副画需要5秒的时间。你的任务是设计一个程序,计算在警察赶来之前(警察到达时皮尔回到了入口也算),他最多能偷到多少幅画。

输入描述 Input Description

第1行是警察赶到得时间,以s为单位。第2行描述了艺术馆得结构,是一串非负整数,成对地出现:每一对得第一个数是走过一条走廊得时间,第2个数是它末端得藏画数量;如果第2个数是0,那么说明这条走廊分叉为两条另外得走廊。数据按照深度优先得次序给出,请看样例

输出描述 Output Description

输出偷到得画得数量

样例输入 Sample Input

60

7 0 8 0 3 1 14 2 10 0 12 4 6 2

样例输出 Sample Output

2

数据范围及提示 Data Size & Hint

s<=600

走廊的数目<=100


dm:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
struct edge{
int lson,rson,cost,val;
}map[1000];
struct in11{
int cost,val;
}s[1000];
int s1;
int n1;
void build(void);
int dfs(int root,int rt);
int dp[1000][700];
int main()
{
int n=1;
cin>>s1;
while(cin>>s[n].cost>>s[n].val)n++;
n--;
n1=0;
build();
memset(dp,-1,sizeof(dp));
int ans=dfs(1,s1);
cout<<ans;
    return 0;
}
void build(void)
{
n1++;
int root=n1;
map[n1].cost=s[n1].cost*2;
map[n1].val=s[n1].val;
if(s[n1].val!=0){map[n1].lson=map[n1].rson=-1; return;}
map[root].lson=n1+1;
build();
map[root].rson=n1+1;
build();
}


int dfs(int root,int rt)
{
if(rt<map[root].cost)return dp[root][rt]=0;
if(dp[root][rt]!=-1)return dp[root][rt];
if(rt==0)return dp[root][rt]=0;
if(map[root].lson==-1){
if(map[root].val*5<=rt-map[root].cost)return dp[root][rt]=map[root].val;
else return dp[root][rt]=(rt-map[root].cost)/5;
}
int time=rt-map[root].cost;
for(int left=0;left<=time;left++){
dp[root][rt]=max(dp[root][rt], dfs(map[root].lson,left)+dfs(map[root].rson,time-left )  );
}
return dp[root][rt];
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值