標籤:org efi open none 時間 splay ons https isp
傳送門
比較奇怪的樹形背包
首先需要處理讀入的問題 這題史詩遞迴讀入
然後遞迴讀入就不用建圖
這題特點是只有葉子有價值 所以背包就不太有用
坑點就是這個人進去還得出來...
而且不能把時間都用完(導致75)
Time cost: 35min
Code:
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 #include<queue> 6 #define ms(a,b) memset(a,b,sizeof a) 7 #define rep(i,a,n) for(int i = a;i <= n;i++) 8 #define per(i,n,a) for(int i = n;i >= a;i--) 9 #define inf 214748364710 using namespace std;11 typedef long long ll;12 typedef double D;13 #define eps 1e-814 ll read() {15 ll as = 0,fu = 1;16 char c = getchar();17 while(c < ‘0‘ || c > ‘9‘) {18 if(c == ‘-‘) fu = -1;19 c = getchar();20 }21 while(c >= ‘0‘ && c <= ‘9‘) {22 as = as * 10 + c - ‘0‘;23 c = getchar();24 }25 return as * fu;26 }27 //head28 const int N = 1005;29 int n,V;30 struct node {31 int val,cst;32 }p[N<<4];33 int dp[N][N];34 35 #define ls x<<136 #define rs x<<1|137 void input(int x) {38 p[x].cst = read() << 1,p[x].val = read();39 if(!p[x].val) input(ls),input(rs);40 }41 42 int dfs(int x,int tot) {43 if(!tot) return 0;44 if(dp[x][tot]) return dp[x][tot];45 //sn46 if(p[x].val) return dp[x][tot] = min(p[x].val,(tot - p[x].cst) / 5);47 //pa48 rep(k,0,tot - p[x].cst)49 dp[x][tot] = max(dp[x][tot],dfs(ls,k) + dfs(rs,tot - p[x].cst - k));50 return dp[x][tot];51 }52 53 int main() {54 int V = read() - 1;55 input(1);56 printf("%d\n",dfs(1,V));57 return 0;58 }View Code
luogu P1270 "訪問"美術館 樹dp