C. Shaass and Lights

http://codeforces.com/contest/294/problem/C

代码:

#include<iostream>

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<vector>

#include<set>

#include<queue>

#include<map>

#include<string>

#include <iomanip>



using namespace std;



const int INF=0x3f3f3f3f;

const long long MOD=1000000007;

const int N=2005;

long long a[N];

vector<int>vt;

long long c[N][N];

int main()

{

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

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

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

    {

        if(j==0) {c[i][j]=1;continue;}

        if(i==j) {c[i][j]=1;continue;}

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

    }

    a[0]=1;

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

    a[i]=(a[i-1]*2)%MOD;

    int n,m;

    while(cin>>n>>m)

    {

        vt.clear();

        for(int i=1;i<=m;++i)

        {

            int tmp;

            cin>>tmp;

            vt.push_back(tmp);

        }

        sort(vt.begin(),vt.end());

        long long ans=1;

        for(unsigned int i=1;i<m;++i)

        {

            int k=vt[i]-vt[i-1]-1;

            if(k>1)

            ans=(ans*a[k-1])%MOD;

        }

        vt.insert(vt.begin(),0);

        vt.push_back(n+1);

        int sum=0;

        for(unsigned int i=0;i<vt.size();++i)

        {

            int k=0;

            if(i>0)

            k=vt[i]-vt[i-1]-1;

            if(sum>0&&k>0)

            ans=(ans*c[sum+k-1+1][k])%MOD;

            sum+=k;

        }

        cout<<ans<<endl;

    }

    return 0;



}

  

你可能感兴趣的:(sha)