欢迎来到SFWR的博客

P2822 组合数问题

——————————————————————————————————————————————————————————

相当于打印杨辉三角后,按是否为倍数转换为01矩阵,再容斥求矩阵和

结果这样只能70pts(unsigned ll)

根据模性质每步对c取模即可

————————————————————————————————————

#include<bits/stdc++.h>
using namespace std;
int t,k;
unsigned long long int c[2001][2001];
int f[2001][2001];
int main()
{
    cin>>t>>k;
    for(int i=0;i<=2000;i++){c[i][0]=c[i][i]=1;}
    for(int i=1;i<=2000;i++)
    for(int j=1;j<=i;j++)
    c[i][j]=(c[i-1][j-1]+c[i-1][j])%k;
    for(int i=1;i<=2000;i++)
    for(int j=1;j<=2000;j++)
    {
    f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
    if(c[i][j]==0&&j<=i)f[i][j]++;    
    }
    //for(int i=0;i<=10;i++){for(int j=0;j<=i;j++)cout<<f[i][j]<<" ";cout<<endl;}
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        cout<<f[a][min(a,b)]<<endl;
    }
}

 

posted @ 2019-07-25 21:41  SFWR  Views(125)  Comments(0Edit  收藏  举报