Free pie (HDU1176) and free pie hdu1176
A simple DP, time is linear, and is a natural sequence. The factors that affect decision-making are only time and position. We already know that the initial position is 5, obtain the state equation dp [I] [j] = max {dp [I] [j] + a [I] [j], dp [I + 1] [j] + a [I] [j], dp [I + 1] [J-1] + a [I] [j], dp [I + 1] [j + 1] + a [I] [j]} must note that it has only 11 locations, so some restrictions must be added, in addition, the array a [t] [x] is used to represent the number of pies at the position x at the t moment. Since the maximum time is not provided, it is worth mentioning that T should be dynamically updated during input: Since he made three decisions in the first second, therefore, dp [I] [j] actually refers to the maximum number of pies obtained when I + 1 s is transferred to position j. Therefore, the final answer is dp [0] [5].
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>#include<vector>using namespace std;const long long INF = 100000000000000000;int n,a[100005][15],x,t,T,dp[100005][15];int main(){ while(~scanf("%d",&n)&&n){ memset(a,0,sizeof(a)); memset(dp,0,sizeof(dp)); T = 0; for(int i=1;i<=n;i++) { scanf("%d%d",&x,&t); a[t][x]++; T = max(T,t); } for(int i=0;i<=10;i++) dp[T][i] = a[T][i]; for(int i=T-1;i>=0;i--){ for(int j=0;j<=10;j++){ dp[i][j] = max(dp[i][j],dp[i+1][j]+a[i][j]); if(j>0) dp[i][j] = max(dp[i][j],dp[i+1][j-1]+a[i][j]); if(j<10) dp[i][j] = max(dp[i][j],dp[i+1][j+1]+a[i][j]); } } printf("%d\n",dp[0][5]); } return 0;}