usaco-3.3-game1-passed
2014-09-16 16:40
323 查看
又是DP,d[i][j]-->d[start][end]
d[i][j]=sum[i][j]-min(d[i][j-1],d[i+1][j])
test data:
d[i][j]=sum[i][j]-min(d[i][j-1],d[i+1][j])
/* ID: qq104801 LANG: C++ TASK: game1 */ #include <iostream> #include <fstream> #include <cstring> #include <vector> #include <queue> #include <stack> #include <algorithm> using namespace std; #define nmax 101 int n; int a[nmax]; int d[nmax][nmax]; int sum[nmax][nmax]; void test() { freopen("game1.in","r",stdin); freopen("game1.out","w",stdout); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) { sum[i][i]=a[i]; for(int j=i+1;j<=n;j++) sum[i][j]=sum[i][j-1]+a[j]; } for(int i=1;i<=n;i++) d[i][i]=a[i]; for(int l=1;l<=n;l++) for(int i=1;i<=n;i++) d[i][i+l]=sum[i][i+l]-min(d[i][i+l-1],d[i+1][i+l]); cout<<d[1] <<" "<<sum[1] -d[1] <<endl; } int main () { test(); return 0; }
test data:
USACO Training Grader Results 5 users online CHN/3 DNK/1 USA/1 USER: cn tom [qq104801] TASK: game1 LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.005 secs, 3452 KB] Test 2: TEST OK [0.005 secs, 3452 KB] Test 3: TEST OK [0.008 secs, 3452 KB] Test 4: TEST OK [0.008 secs, 3452 KB] Test 5: TEST OK [0.011 secs, 3452 KB] Test 6: TEST OK [0.008 secs, 3452 KB] Test 7: TEST OK [0.008 secs, 3452 KB] Test 8: TEST OK [0.005 secs, 3452 KB] Test 9: TEST OK [0.005 secs, 3452 KB] Test 10: TEST OK [0.008 secs, 3452 KB] Test 11: TEST OK [0.005 secs, 3452 KB] Test 12: TEST OK [0.008 secs, 3452 KB] Test 13: TEST OK [0.008 secs, 3452 KB] Test 14: TEST OK [0.005 secs, 3452 KB] Test 15: TEST OK [0.005 secs, 3452 KB] Test 16: TEST OK [0.008 secs, 3452 KB] All tests OK. YOUR PROGRAM ('game1') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations. Here are the test data inputs: ------- test 1 ---- 6 4 7 2 9 5 2 ------- test 2 ---- 2 134 187 ------- test 3 ---- 20 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ------- test 4 ---- 3 73 126 152 ------- test 5 ---- 30 105 57 64 79 188 102 52 145 188 2 163 147 174 163 198 9 133 159 184 104 70 19 57 174 184 57 154 123 106 129 ------- test 6 ---- 55 172 15 184 147 51 16 98 162 17 199 43 32 28 134 141 63 124 121 152 8 74 63 121 102 149 134 90 4 3 113 109 194 175 157 87 7 175 71 125 62 81 53 94 68 18 184 65 153 22 20 177 125 82 169 155 ------- test 7 ---- 80 110 130 89 22 43 15 55 126 176 43 66 36 69 194 1 66 132 175 63 34 96 178 100 198 184 64 178 144 125 111 49 188 118 178 8 7 73 18 173 73 31 197 109 12 118 146 197 49 92 13 90 61 76 31 53 6 121 68 126 52 189 92 107 168 3 1 98 94 154 150 9 74 118 35 157 43 163 68 172 74 ------- test 8 ---- 99 12 115 150 135 150 121 38 148 148 6 104 56 125 178 176 10 45 37 127 10 113 58 170 149 157 52 18 112 73 177 44 135 143 161 99 165 103 114 110 16 169 194 125 53 103 87 135 26 128 191 113 154 163 46 35 108 195 106 96 178 70 197 93 71 96 145 4 37 152 143 102 163 109 117 70 130 33 63 31 76 190 28 161 61 124 100 19 173 20 79 33 177 32 188 96 139 179 108 110 ------- test 9 ---- 100 72 150 157 13 64 86 92 11 169 162 107 163 42 61 154 103 166 181 4 11 94 132 14 53 88 190 3 157 102 88 25 189 151 99 147 109 12 200 4 162 94 58 51 81 29 45 81 165 28 200 116 12 134 163 72 159 26 1 64 14 125 131 181 136 19 76 198 43 188 64 24 3 34 187 194 193 190 147 175 85 142 91 7 20 95 183 43 65 147 196 112 86 106 173 71 141 185 58 64 131 ------- test 10 ---- 2 10 1 ------- test 11 ---- 6 4 7 2 9 5 2 ------- test 12 ---- 20 6 6 11 8 16 7 1 20 2 16 9 4 20 6 14 1 14 13 6 19 ------- test 13 ---- 30 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 ------- test 14 ---- 50 39 33 6 16 15 12 21 27 9 30 12 6 5 33 45 23 30 44 31 43 33 12 34 27 44 5 38 13 33 2 1 22 35 7 37 49 19 7 26 27 36 38 33 41 20 27 13 49 21 44 ------- test 15 ---- 100 39 197 16 12 149 125 195 189 38 102 128 27 60 132 105 9 54 56 146 193 66 88 85 121 99 19 104 8 177 70 41 17 68 57 29 17 181 24 6 20 126 134 46 185 67 151 194 120 8 140 113 73 28 197 194 126 16 98 134 193 167 174 10 35 31 38 51 13 62 57 32 187 191 78 172 58 30 167 177 37 107 90 110 135 88 104 62 103 3 195 97 169 170 106 5 2 144 56 15 6 ------- test 16 ---- 100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 Keep up the good work! Thanks for your submission!
相关文章推荐
- USACO 3.3 A Game
- usaco-3.3-shopping-passed
- USACO 3.3 A Game (game1)
- USACO 3.3 A Game
- usaco-3.3-camelot-passed
- usaco 3.3 game1 2008.11.7
- usaco-3.3-range-passed
- USACO 3.3 A Game
- usaco Chapter 3 section 3.3 A game
- USACO Section 3.3: A Game
- usaco-4.3-buylow-passed
- usaco-5.3-milk4-passed
- BZOJ2102 : [Usaco2010 Dec]The Trough Game
- usaco3.3欧拉路的胡乱总结
- [USACO3.3]商店购物 Shopping Offers
- USACO section 3.3 Shopping Offers(DP或最短路)
- bzoj:1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- usaco-4.2-ditch-passed
- bzoj2102 [Usaco2010 Dec]The Trough Game
- [USACO 2012 January Gold] Video Game Combos