UVa 11806 - Cheerleaders

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=226&problem=2906&mosmsg=Submission+received+with+ID+11832924

容斥原理  第二题  水!

代码:

#include<iostream>

#include<cstring>

#include<cstdio>

#include<string>

#include<set>

#include<map>

#include<cmath>

#include<algorithm>

#include<vector>

#include<cmath>

#include<queue>

#include<stack>



//#define ull unsigned long long

#define ll long long



using namespace std;



const int INF=0x3f3f3f3f;

const int MOD=1000007;



const double eps=1e-6;

const int N=500;

int c[N][N];

int F(int x)

{

    if(x>=MOD)

    {

        x=x%MOD;

        return x;

    }

    while(x<0)

    {

        x+=MOD;

    }

    return x;

}

int main()

{

    //freopen("data.in","r",stdin);

    memset(c,0,sizeof(c));

    for(int i=0;i<N;++i)

    for(int j=0;j<=i;++j)

    if(i==j||j==0)

    c[i][j]=1;

    else

    c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;



    int T;

    cin>>T;

    for(int w=1;w<=T;++w)

    {

        printf("Case %d: ",w);

        int n,m,k;

        cin>>n>>m>>k;

        if(k>n*m||k<2)

        cout<<"0"<<endl;

        else

        {

            int sum=0;

            sum+=(2*c[n*m-n][k]+2*c[n*m-m][k]);//cout<<sum<<endl;

            sum-=(c[n*m-n-n][k]+c[n*m-m-m][k]+4*c[n*m-m-n+1][k]);

            sum+=(2*c[n*m-m-m-n+2][k]+2*c[n*m-m-n-n+2][k]);

            sum-=(c[n*m-n-n-m-m+4][k]);

            cout<<F(c[n*m][k]-sum)<<endl;

        }



    }

    return 0;

}

  

你可能感兴趣的:(uva)