标签:des style blog http java color
很简单,就是数塔的变形。
数塔从上到下分别对应时间t时刻x位置掉落的馅饼。
然后从下往上算即可。
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24502 Accepted Submission(s): 8288
1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 using namespace std; 6 7 const int maxn = 100000; 8 int a[maxn + 10][11]; 9 int max(int a, int b, int c) 10 { 11 a = max(a, b); 12 return max(a, c); 13 } 14 15 int main(void) 16 { 17 #ifdef LOCAL 18 freopen("1176in.txt", "r", stdin); 19 #endif 20 21 int n; 22 while(scanf("%d", &n) == 1 && n) 23 { 24 memset(a, 0, sizeof(a)); 25 int i, Tmax = 0; //用来记录T的最大值 26 for(i = 0; i < n; ++i) 27 { 28 int x, T; 29 scanf("%d %d", &x, &T); 30 ++a[T][x]; 31 if(T > Tmax) 32 Tmax = T; 33 } 34 35 int j; 36 for(i = Tmax; i >= 1; --i) 37 for(j = 0; j <= 10; ++j) 38 { 39 if(j == 0) 40 { 41 a[i - 1][j] += max(a[i][j], a[i][j + 1]); 42 continue; 43 } 44 if(j == 10) 45 { 46 a[i - 1][j] += max(a[i][j - 1], a[i][j]); 47 continue; 48 } 49 a[i - 1][j] += max(a[i][j - 1], a[i][j], a[i][j + 1]); 50 } 51 52 cout << a[0][5] << endl; 53 } 54 return 0; 55 }
标签:des style blog http java color
原文地址:http://www.cnblogs.com/AOQNRMGYXLMV/p/3821306.html