"BZOJ1028" "JSOI2007" mahjong Violence

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.