标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 228 Accepted Submission(s): 138
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <ctime> 6 #include <iostream> 7 #include <map> 8 #include <set> 9 #include <algorithm> 10 #include <vector> 11 #include <deque> 12 #include <queue> 13 #include <stack> 14 using namespace std; 15 typedef long long LL; 16 typedef double DB; 17 #define MIT (2147483647) 18 #define MLL (1000000000000000001LL) 19 #define INF (1000000001) 20 #define For(i, s, t) for(int i = (s); i <= (t); i ++) 21 #define Ford(i, s, t) for(int i = (s); i >= (t); i --) 22 #define Rep(i, n) for(int i = (0); i < (n); i ++) 23 #define Repn(i, n) for(int i = (n)-1; i >= (0); i --) 24 #define mk make_pair 25 #define ft first 26 #define sd second 27 #define puf push_front 28 #define pub push_back 29 #define pof pop_front 30 #define pob pop_back 31 #define sz(x) ((int) (x).size()) 32 #define clr(x, y) (memset(x, y, sizeof(x))) 33 inline void SetIO(string Name) 34 { 35 string Input = Name + ".in"; 36 string Output = Name + ".out"; 37 freopen(Input.c_str(), "r", stdin); 38 freopen(Output.c_str(), "w", stdout); 39 } 40 41 inline int Getint() 42 { 43 char ch = ‘ ‘; 44 int Ret = 0; 45 bool Flag = 0; 46 while(!(ch >= ‘0‘ && ch <= ‘9‘)) 47 { 48 if(ch == ‘-‘) Flag ^= 1; 49 ch = getchar(); 50 } 51 while(ch >= ‘0‘ && ch <= ‘9‘) 52 { 53 Ret = Ret * 10 + ch - ‘0‘; 54 ch = getchar(); 55 } 56 return Ret; 57 } 58 59 const int N = 2050; 60 int n, F[N]; 61 int Dp[N]; 62 63 inline void Solve(); 64 65 inline void Input() 66 { 67 int TestNumber = Getint(); 68 while(TestNumber--) 69 { 70 n = Getint(); 71 For(i, 1, n - 1) F[i] = Getint(); 72 Solve(); 73 } 74 } 75 76 inline void Solve() 77 { 78 For(i, 2, n - 1) F[i] -= F[1]; 79 Dp[0] = 0; 80 For(i, 1, n - 2) 81 { 82 Dp[i] = F[i + 1]; 83 For(j, 1, (i / 2) + 1) 84 Dp[i] = max(Dp[i], Dp[j] + Dp[i - j]); 85 } 86 printf("%d\n", Dp[n - 2] + n * F[1]); 87 } 88 89 int main() 90 { 91 Input(); 92 //Solve(); 93 return 0; 94 }
2015ACM/ICPC亚洲区长春站 G hdu 5534 Partial Tree
标签:
原文地址:http://www.cnblogs.com/StupidBoy/p/4937416.html