zoukankan      html  css  js  c++  java
  • tyvj4541 zhx 提高组P1

    背景

    提高组

    描述

    在一个N×M的棋盘上,要求放置K个车,使得不存在一个车同时能被两个车攻击。问方案数。

    输入格式

    一行三个整数,N,M,K。

    输出格式

    一行一个整数,代表答案对1000001取模之后的值。

    备注

    【样例输入1】
    4 5 2
    【样例输出1】
    190
    【样例输入2】
    2 3 3
    【样例输出2】
    6
    【样例输入3】
    6 7 20
    【样例输出3】
    0
    【样例输入4】
    23 37 39
    【样例输出4】
    288688
    【样例解释】
    【数据规模与约定】
    对于100%的数据,1≤N,M≤50,1≤K≤100。

    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int maxn = 55,mod = 1000001;
    int n,m,k,f[2][maxn<<1][maxn<<1][maxn<<1],ans,cnt;
    int main(){
        cin>>n>>m>>k;
        f[0][0][0][0] = 1;
        for(int i = 1;i <= n;i++){
            cnt ^= 1;
            for(int j = 0;j <= n<<1;j++){
                for(int l = 0;l <= n<<1;l+=2){
                    for(int p = 0;p <= n;p++){
                        f[cnt][j][l][p] = f[cnt^1][j][l][p];
                        if(j > 0) f[cnt][j][l][p] += f[cnt^1][j-1][l][p]*(m-j-p-l+1);
                        if(p > 0) f[cnt][j][l][p] += f[cnt^1][j+1][l][p-1]*(j+1);
                        if(l > 1) f[cnt][j][l][p] += (f[cnt^1][j][l-2][p]*(m-j-l-p+2)*(m-j-l-p+1))>>1;
                        f[cnt][j][l][p] %= mod;
                        if(i == n && j + l + (p<<1) == k){
                            ans = (ans + f[cnt][j][l][p]) % mod;
                        }
                    }
                }
            }
        }
        cout<<ans;
        return 0;
    } 
  • 相关阅读:
    MySQL数据库中的delete语句
    记录Jmeter集成Jenkins运行Ant做接口监听
    测试数据随机生成器(离线)
    python正则表达式
    字典、数据结构化
    python复制、浅拷贝、深拷贝
    python-list:列表-元组-字符串
    自动部署shell(结合Jenkins)
    linux问题记录
    Python操作excel
  • 原文地址:https://www.cnblogs.com/hyfer/p/5689440.html
Copyright © 2011-2022 走看看