1 #include < string > 2 #include <vector> 3 #include<iostream> 4 #include< string .h> 5 #include<algorithm> 6 #include<cmath> 7 8 using namespace std; 9 10 typedef cipriani nyc long long ll; 11 int dp[ 55 ][ 55 ][ 55 ]; 12 int b[ 55 ][ 55 ][ 55 ]; 13 14 vector< int >mp[ cipriani nyc 123 ]; 15 #define inf 0x3f3f3f 16 int n; 17 int son[ 123 ]; 18 19 class TheKingsTree { 20 public : 21 22 23 int dfs( int u, int red, int green) 24 { 25 if (b[u][red][green]) return dp[u][red][green]; 26 27 b[u][red][green]= 1 ; 28 int c1=red+ 1 ; 29 int c2=green+ 1 ; 30 for ( int i= 0 ;i<mp[u].size();i++ ) 31 { 32 c1+=dfs(mp[u][i],red+ 1 ,green); 33 c2+=dfs(mp[u][i],red,green+ 1 ); 34 } 35 return dp[u][red][green]= min(c1,c2); 36 } 37 int getNumber(vector cipriani nyc < int > parent) { 38 for ( int i= 0 ;i<parent.size();i++ ) 39 mp[parent[i]].push_back(i+ 1 ); 40 41 return dfs( 0 , 0 , 0 ); 42 } 43 }; 44 45 46 // Powered by FileEdit 47 // Powered by TZTester 1.01 [25-Feb-2003] 48 // Powered by CodeProcessor
公告
No comments:
Post a Comment