【codevs1163】访问艺术馆

problem

solution

codes

//f[i,j]表示用j秒回到i最多拿几幅画
//链式建树
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1010;
int tot, n(1), f[maxn][maxn];//n是节点编号
void dp(int root){
    int time, pic;
    cin>>time>>pic;
    time *= 2;  //走廊要走两遍
    if(!pic){
        int lch(++n), rch(++n);
        dp(lch);
        dp(rch);
        //?无法确定时间,因为祖先节点时间没有考虑进去,所以当前剩下的时间不知道,所以枚举所有状态
        for(int i = time; i<= tot; i++)
            for(int j = 0; j <= i-time; j++)
                f[root][i]=max(f[root][i], f[lch][j]+f[rch][i-time-j]);
    }else{
        for(int i = time; i <= tot; i++)
            f[root][i] = min(pic,(i-time)/5);
    }
}
int main(){
    cin>>tot;
    dp(1);
    cout<<f[1][tot]<<"\n";
    return 0;
}
posted @ 2018-05-27 20:41  gwj1139177410  阅读(139)  评论(0编辑  收藏  举报
选择