hdu 3010

来源:互联网 发布:浙江大学软件学院硕士 编辑:程序博客网 时间:2024/05/22 06:46

dp[n]表示n乘以n棋盘中,一个对角线都不放的方案数,然后当新增一行一列时候,新增的那一列放到第i个位置

那么那个放的总共有n-1种放法

然后所放的那个位置关于对角线对称的那个点:有两种可能放还是不放

如果对称点放那么就相当于dp[n-2],不放就相当于dp[n-1]

//  Created by Chenhongwei on 2016-04-15 Friday 00:08//  Copyright (c) 2016 Chenhongwei. All rights reserved.#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <climits>#include <queue>#include <cmath>#include <map>#include <set>#include <stack>#include <vector>#include <sstream>#include <algorithm>#define root 1,n,1#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;const int inf=1e9;const int mod=20090818;const int maxn=1e5+100;typedef long long ll;typedef unsigned long long ull;ll c[1010][1010];ll dp[1010];int main(){//ios::sync_with_stdio(false);    // freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);for(int i=1;i<=1000;i++)c[i][0]=1,c[i][i]=1;for(int i=2;i<=1000;i++)for(int j=1;j<i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;dp[0]=1,dp[1]=0,dp[2]=1;for(int i=3;i<=1000;i++)dp[i]=(i-1)*(dp[i-2]+dp[i-1])%mod;int n,m;while(scanf("%d%d",&n,&m)!=EOF){ll ans=0;for(int i=0;i<=m;i++)ans=(ans+c[n][i]*dp[n-i])%mod;printf("%lld\n",ans);}return 0;}


0 0
原创粉丝点击