Test instructions
Fruit Ninja, give you the occurrence time of n fruit, appear position, and whether he is good fruit, cut to good fruit +1, cut to bad fruit-1, cut continuously to three times above the score doubled.
Can only cut one knife at a time, the interval between two knives is greater than or equal to M
Ask how to arrange to make the highest score;
Solution: First to find out every second shot can get the biggest score, double violence,
Then use DP to find the time of the shot;
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<stdio.h>using namespacestd;ints[10010][ -],maxn[10010],vis1[10010],dp[10010],vis2[10010];intMain () {intT,n,m,a,b,c; scanf ("%d",&T); intt=1; while(t--) {scanf ("%d%d",&n,&m); memset (s),0,sizeof(s)); memset (Vis1,0,sizeof(VIS1)); memset (MAXN,0,sizeof(MAXN)); memset (Vis2,0,sizeof(VIS2)); for(intI=0; i<n; i++) {scanf ("%d%d%d",&a,&b,&c); if(b==0) {S[a][c]=1; } Else if(b==1) {S[a][c]=-1; } Vis1[a]=1; if(C>vis2[a])//optimize to figure out the right-most position{Vis2[a]=C; } } for(intI=1; i<=10000; i++)//figure out the maximum number of points that can be cut at each second of the shot. { if(vis1[i]==1) { intmax1=-1; for(intj=1; j<=vis2[i]; J + +) { intf=0; intsum=0; for(intK=j; k<=vis2[i]; k++) { if(s[i][k]==1) {f++; } Else if(s[i][k]==-1) { if(f>=3) {sum+=f*2; if(sum>max1) {Max1=sum; } } Else{sum+=F; if(sum>max1) {Max1=sum; }} F=0; Sum-=1; if(sum>max1) {Max1=sum; } } } if(f>0) { if(f>=3) {sum+=f*2; if(sum>max1) {Max1=sum; } } Else{sum+=F; if(sum>max1) {Max1=sum; } }}} Maxn[i]=Max1; }} memset (DP,0,sizeof(DP)); for(intI=1; i<=10000; i++)//DP, decide which second shot { if(i>m) {Dp[i]=max (dp[i-1],dp[i-m-1]+maxn[i]);//if it's a shot, it's related to the state of his i-m-1. } Else{Dp[i]=max (dp[i-1],maxn[i]); }} printf ("Case %d:", t++); printf ("%d\n", dp[10000]); } return 0;}
2012 "Wave Cup" the third ACM University Student Program Design competition in Shandong province Fruit Ninja I