Reprint Please specify the source Thank you: http://blog.csdn.net/vmurder/article/details/42921985
Title: give you a deck of cards, ask whether it is a draw (that is, add a card can "Hu"), if it is, the output to touch which cards can hu, not output "no"
Hu rules: The first need to have two of the same number of cards are eliminated, and then can be three of the same card to eliminate, can also be three consecutive label cards to eliminate, eliminate the hu.
For example, 22 444555 789 is the HU card.
Exercises
Violent enumeration and then touch which card will be able to Hu,
Then the violent elimination of cards.
Code:
#include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define N 50100#define mod 10007#define inf 0x3f3f3f3fusing namespace std;int sk[n],sum[n],n,m;bool Check ( int mid) {int use=0,i,j,len=0;for (i=1;i<=n;i++) {len+=sk[i];if (Len+sk[i+1]>mid) use++,len=0;} if (use>m) return 0;else return 1;} int F[2][n];int Now,last;int Main () {freopen ("test.in", "R", stdin); int i,j,k;int l=0,r=0,mid,ans;scanf ("%d%d", &n, &M); for (i=1;i<=n;i++) {scanf ("%d", &sk[i]), Sum[i]=sum[i-1]+sk[i];l=max (L,sk[i]), r+=sk[i];} while (L<r) {if (r-l<=3) {for (i=r;i>=l;i--) if (check (i)) ans=i;break;} Mid=l+r>>1;if (check (mid)) R=mid;else l=mid+1;} printf ("%d", Mid=ans), Ans=0;f[now=1][0]=1;int top;for (i=1;i<=m+1;i++) {now^=1,last^=1;k=0,top=i-2;for (j=i;j <=n;j++) {k+=f[last][j-1],k%=mod;while (sum[j]-sum[top+1]>mid) {k-=f[last][++top];if (k<0) K+=mod;} F[now][j]=k;} Ans+=f[now][n],ans%=mod;} printf ("%d\n", ans); return 0;}
"BZOJ1028" "JSOI2007" mahjong Violence