Vijos 1932 重要的誓言

来源:互联网 发布:90年代网络歌曲 编辑:程序博客网 时间:2024/05/16 16:58

【题意】T组数据,输出方程a[1]+a[2]+a[3]+...+a[k]=n满足a[i] and a[i+1] = a[i+1]的解的个数

1<=T<=5,3<=k<=100000,3<=n<=10000

【分析】


【代码】

#include <cstdio>

#include <cstring>

#include <cstdlib>

 

using namespace std;

 

const int N=10001;

const int W=14;

const int K=100001;

const int LM=1000000009;

 

int t,c,n;

long long f[W+1][N];

 

int main(void)

{

    scanf("%d",&t);

    for (;t--;)

    {

        scanf("%d%d",&c,&n);

        memset(f,0,sizeoff);

        for (inti=0;i<=c;i++) if (i>n) break; else f[0][i]=1;

        for (inti=0;i<W;i++) for (int j=0;j<=n;j++) for (int k=0;k<=c;k++) 

        if(j+k*(1<<i+1)>n) break; 

        elsef[i+1][j+k*(1<<i+1)]=(f[i+1][j+k*(1<<i+1)]+f[i][j])%LM;

        printf("%lld\n",f[W-1][n]);

    }

    return 0;

}

【小结】

  1. 对于二进制运算,最基本的可以暴力解决,其他要从位的角度考虑,例如线段树维护的、字典树维护的等等,抓住位运算的特性

  2. 对拍的效果还是非常明显的,有时候本地调试暴空间都不知道,要尝试大数据,多尝试数据……

  3. 数列中,a[i] and a[i+1]=a[i+1]所起到的是定序的作用

0 0
原创粉丝点击