8
7
2015
4

BZOJ 1801: [Ahoi2009]chess 中国象棋

Description

在N行M列的棋盘上,放若干个炮可以是0个,使得没有任何一个炮可以攻击另一个炮。 请问有多少种放置方法,中国像棋中炮的行走方式大家应该很清楚吧.
 
一道DP 开始向一般的状态压缩DP ,结果数组开不下。。。
用两维分别表示有两个棋子的列数和一个棋子的列数,没有棋子的可以用总列数减去其余两种;
分了5种转移的情况:
1.一个棋子的加一个;
2.零个棋子的加一个;
3.两列一个棋子的分别加一;
4.两列零个棋子分别加一;
5.一列零个棋子一列一个棋子分别加一;
分情况转移就行了。
/**************************************************************
    Problem: 1801
    User: 1115825064
    Language: C++
    Result: Accepted
    Time:292 ms
    Memory:1444 kb
****************************************************************/
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;
 
long long f[2][105][105];
 
int n,m;
const int mod=9999973;
 
int main()
{
//  freopen("1.txt","r",stdin);
    scanf("%d%d",&n,&m);
    f[0][0][0]=1;
    for(int i=0;i<n;++i)
    {
        memset(f[~i&1],0,sizeof(f[i&1]));
        for(int j=0;j<=m;++j)
            for(int k=0;k+j<=m;++k)
            {
                int l=m-k-j;
                 
                f[~i&1][j][k]+=f[i&1][j][k],f[~i&1][j][k]%=mod;
                if(j>1)f[~i&1][j-2][k+2]+=(f[i&1][j][k]*j*(j-1))/2,f[~i&1][j-2][k+2]%=mod;
                if(j>0)f[~i&1][j-1][k+1]+=f[i&1][j][k]*j,f[~i&1][j-1][k+1]%=mod; 
                if(l>0)f[~i&1][j+1][k]+=f[i&1][j][k]*l,f[~i&1][j+1][k]%=mod;
                if(l>1)f[~i&1][j+2][k]+=(f[i&1][j][k]*l*(l-1))/2,f[~i&1][j+2][k]%=mod;
                if(l>0&&j>0)f[~i&1][j][k+1]+=f[i&1][j][k]*l*j,f[~i&1][j][k+1]%=mod;
            }
    }
    long long ans=0;
    for(int j=0;j<=m;++j)
        for(int k=0;k+j<=m;++k)
        {
            ans+=f[n&1][j][k];
            ans%=mod;
        }
    printf("%lld",ans);
    return 0;
}

 

Category: 未分类 | Tags: | Read Count: 459
Avatar_small
Comprar seguidores 说:
2020年9月02日 20:21

Eu me pergunto como você ficou tão bom. HaHa! Este é realmente um blog fascinante, muitas coisas em que posso me aprofundar. Só quero dizer que seu design é tão perfeito!

Avatar_small
Matthew Wade 说:
2025年3月25日 17:56

Greetings, May I grab your page picture and implement it on my own blog page? 바카라사이트

Avatar_small
Matthew Wade 说:
2025年4月02日 21:00

This may be the appropriate weblog for anybody who hopes to discover this topic. You realize so much its virtually challenging to argue to you (not too I actually would want…HaHa). You actually put a new spin with a topic thats been discussing for a long time. Wonderful stuff, just fantastic! binary options signals

Avatar_small
Matthew Wade 说:
2025年4月13日 17:18

<p>
But yeah Many thanks for taking the time to discuss this, I feel strongly about it and really like learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. <a href="https://blog.vfxalert.com/en/t/top-3-strategies-for-binary-options-with-vfxalert-signals">Trending Strategy</a></p>


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com