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