Think:
1知识点:dp
2题意分析:建立二维时间位置数组,然后从最后掉落时间开始,金字塔向上更新
3反思:注意不要数组越界,注意不同题目for循环更新方向不要习惯性i++
以下为Accepted代码
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int Max(int a, int b, int c);
int dp[101400][14];
int main(){
int n, x, t, m, i, j;
while(scanf("%d", &n) && n){
memset(dp, 0, sizeof(dp));
m = 0;
for(i = 0; i < n; i++){
scanf("%d %d", &x, &t);
dp[t][x]++;
m = max(m, t);
}
for(i = m-1; i >= 0; i--){
dp[i][0] += max(dp[i+1][0], dp[i+1][1]);
for(j = 1; j <= 9; j++){
dp[i][j] += Max(dp[i+1][j-1], dp[i+1][j], dp[i+1][j+1]);
}
dp[i][10] += max(dp[i+1][9], dp[i+1][10]);
}
printf("%d\n", dp[0][5]);
}
return 0;
}
int Max(int a, int b, int c){
int t1 = max(a, b);
int t = max(t1, c);
return t;
}