[Title] box staining solution (inclusion and exclusion + ingenious classification)

[Title] box staining solution (inclusion and exclusion + ingenious classification)

At first I thought it was a road inclusion and exclusion, wrote this wrong procedure


int main(){
      pre(1e5);
      while(~scanf("%d%d",&n,&m)){
        int ans=0;
        for(register int t=m,delta;t<=n;++t){
          delta=0;
          for(register int k=1,d2;k<=n/t;++k){
            d2=1ll*c(n/t,k)*(n-k*t+1)%mod*bin[n-k*t]%mod;
            if(k&1) d2=mod-d2;
            delta+=d2;
            while(delta>=mod)delta-=mod;
          }
          if((t-m)&1) delta=mod-delta;
          ans=(ans+delta)%mod;
        }
        printf("%d\n",ans);
      }
      return 0;
}

This is clearly wrong, inclusion and exclusion sets of inclusion and exclusion, I do not know why I'm to pay up (may be on a sample)

Later, I received a revelation by Aberdeen (bai) fine (du) Si (ti) test (jie)

Set \ (dp (n) \) of \ (n-\) number of a program when

If I had known earlier \ (n-1 \) program, now you know \ (n \) program, and how to do?

Obviously, there must be a \ (2dp (n-1) \) contribution, meaning that in followed by a block, it does not matter what color

I think by then (ti) test (jie) found, it can be classified:

  • Add the phrase does not work, add this one to meet without lawful conditions did not contribute, directly added like, what color does not matter, so that \ (2dp (n-1) \)

  • Plus to have an effect, that is to say, the entire sequence of only the suffix \ (m \) elements helpful, others are soy sauce, then back to Imperial \ (m \) one is red, and now the problem is in front of \ ( nm \) requirement can not have an effect, so as to meet the classification we have here.

    So is the total - not legitimate chant, but wait a minute, if I say that in front of \ (nm \) th and the latter \ (m \) linked together, and it will not add to the effect of the classification repeat. I penultimate to Imperial \ (m + 1 \) is blue, the total front \ (2 ^ {nm-1 } -dp (nm-1) \) contributes to the.

    You may ask, that there may be a legitimate program that is the inverse of \ (m + x \) a sequence satisfies a condition makes the whole ah, this program go? This solution was placed in the first category, because in that case, the last block does not matter what color, so that the entire sequence is not less condition is not satisfied.

Therefore, direct recursive:
\ [DP (X) = 2DP (. 1-X) + 2 ^ {}. 1 XM--dp (XM-. 1) \]
Initial conditions \ (dp (m) = 1 \)

//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;  typedef long long ll;
inline int qr(){
      register int ret=0,f=0;
      register char c=getchar();
      while(c<48||c>57)f|=c==45,c=getchar();
      while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
      return f?-ret:ret;
}
const int maxn=1e5+5;
const int mod=1e9+7;
int bin[maxn],dp[maxn];
int n,m;

int main(){
      for(register int t=bin[0]=1;t<=100000;++t){
        bin[t]=bin[t-1]<<1;
        while(bin[t]>=mod) bin[t]-=mod;
      }
      while(~scanf("%d%d",&n,&m)){
        dp[m]=1;
        for(register int t=m+1;t<=n;++t){
          dp[t]=dp[t-1]<<1;
          while(dp[t]>mod) dp[t]-=mod;
          dp[t]+=bin[t-m-1];
          while(dp[t]>mod) dp[t]-=mod;
          if(t-m-1>=m) dp[t]+=mod-dp[t-m-1];
          while(dp[t]>mod) dp[t]-=mod;
        }
        printf("%d\n",dp[n]);
      }
      return 0;
}

Guess you like

Origin www.cnblogs.com/winlere/p/11415448.html