Submission #85201

#TimeUsernameProblemLanguageResultExecution timeMemory
85201zoooma13Biochips (IZhO12_biochips)C++14
0 / 100
3 ms512 KiB
#include <bits/stdc++.h> using namespace std; #define MAX_N 25 #define MAX_M 15 #define INF 0x3f3f3f3f int N ,M; int A ,B; int Mem[MAX_N]; vector <int> Adj[MAX_N]; int dp[MAX_M][MAX_N]; int Solve(int v ,int m) { if(Adj[v].empty()) return (m == 1 ? Mem[v] : -INF); if(~dp[m][v]) return dp[m][v]; int dp_new[m+1] ,dp_all[m+1] = {0}; for(int i : Adj[v]) { memset(dp_new ,-INF ,sizeof dp_new); for(int j=1; j<=m; j++) for(int h=0; h<=m-j; h++) dp_new[j+h] = max(dp_new[j+h] ,dp_all[h] + Solve(i ,j)); for(int h=0; h<=m; h++) dp_all[h] = max(dp_all[h] ,dp_new[h]); } return dp[m][v] = (m == 1 ? max(dp_all[m] ,Mem[v]) : dp_all[m]); } int main() { scanf("%d%d",&N,&M); assert(N < MAX_N && M < MAX_M); int root; for(int i=0; i<N; i++) { scanf("%d%d",&A,&B); Mem[i+1] = B; if(A == 0) root = i+1; else Adj[A].push_back(i+1); } memset(dp ,-1 ,sizeof dp); printf("%d\n",Solve(root ,M)); }

Compilation message (stderr)

biochips.cpp: In function 'int main()':
biochips.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M); assert(N < MAX_N && M < MAX_M);
     ~~~~~^~~~~~~~~~~~~~
biochips.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&A,&B);
         ~~~~~^~~~~~~~~~~~~~
biochips.cpp:54:11: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
     printf("%d\n",Solve(root ,M));
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...