201502028 Demo Game

Source: Internet
Author: User

Konjac Konjac said only after looking at the problem a off the first question ...

T1

The main idea: the binary of a number a[] represents a set (a[]=5= (101) 2, which represents the set {1,3}), and the number of subsets in a subset of A[i] that do not meet any one of a[i-b[i]]~a[i-1].

Idea: Search for each subset, save the last occurrence of the various collections, if outside the requested range can be taken, update the array, otherwise it can not be taken, and then output on it. Because the bit operation is a slag, so the use of the DFS (adjust the small constant, there are two measures, one is to the decimal number of this subset when the parameters are passed and changed, and the second is to save 2 of the array of several square, more than the number of times the bitwise operation is faster. ), the effect is good, no timeout.

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intla[100001]={0},er[ -]={0},a[100001]={0},b[100001]={0},ci=0, jie[ -]={0};voidZerintx) {    intI=0; memset (er,0,sizeof(er));  while(x>0)    {        if(%2==1)        {            ++er[0];er[er[0]]=i; } x>>=1; ++i; }}voidWorkintIintXintt) {    intJ; if(i>er[0])    {        if(la[t]<x-b[x]&&t>0)           ++CI; La[t]=x; return; } Work (I+1, x,t); Work (I+1, x,t+jie[er[i]+1]);}intMain () {Freopen ("hope.in","R", stdin); Freopen ("Hope.out","W", stdout); intn,i,j; jie[1]=1;  for(i=2; i<= +; ++i) jie[i]=jie[i-1]<<1; scanf ("%d",&N);  for(i=1; i<=n;++i) {scanf ("%d%d",&a[i],&B[i]); Zer (A[i]); CI=0; Work (1I0); printf ("%d\n", CI);    } fclose (stdin); Fclose (stdout);}
View Code

201502028 Demo Game

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.