P2051 [AHOI2009]中国象棋 大力DP

状压个啥$qwq$


 

思路:大力$DP$

提交:2次(自信的开了$int$)

题解:(见注释)

#include<cstdio>
#include<iostream>
using namespace std;
#define ull unsigned long long
#define ll long long
#define R register ll
#define pause (for(R i=1;i<=10000000000;++i))
#define In freopen("NOIPAK++.in","r",stdin)
#define Out freopen("out.out","w",stdout)
namespace Fread {
static char B[1<<15],*S=B,*D=B;
#ifndef JACK
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
#endif
inline int g() {
    R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
    if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return (ch<=36||ch>=127);}
inline void gs(char* s) {
    register char ch; while(isempty(ch=getchar()));
    do *s++=ch; while(!isempty(ch=getchar()));
}
} using Fread::g; using Fread::gs;
const int N=110,M=9999973;
int n,m,ans;
ll f[N][N][N];
//f[i][j][k]:所处行编号i,含有一个棋子的列数j,含有两个棋子的列数k 
signed main() {
    n=g(),m=g(); f[0][0][0]=1;
    for(R i=1;i<=n;++i) for(R j=0;j<=m;++j) for(R k=0;k<=m-j;++k){
        f[i][j][k]+=f[i-1][j][k];
        //不填棋子 
        if(j>=1) f[i][j][k]+=f[i-1][j-1][k]*(m-k-j+1);                        
        //选空列填一个棋子 
        if(k>=1) f[i][j][k]+=f[i-1][j+1][k-1]*(j+1);
        //选含有一个棋子的某列 
        if(j>=2) f[i][j][k]+=f[i-1][j-2][k]*(m-k-j+2)*(m-k-j+1)/2;
        //选两个空列分别填一个棋子 
        if(k>=1) f[i][j][k]+=f[i-1][j][k-1]*(m-k-j+1)*j;
        //选一个空列和含有一个棋子的某列分别填一个棋子 
        if(k>=2) f[i][j][k]+=f[i-1][j+2][k-2]*(j+2)*(j+1)/2;
        //选含有一个棋子的某两列分别填一个棋子  
        f[i][j][k]%=M;
    } for(R j=0;j<=m;++j) for(R k=0;k<=m-j;++k) ans=(ans+f[n][j][k])%M;
    printf("%d\n",ans);
}

2019.07.17

转载于:https://www.cnblogs.com/Jackpei/p/11204407.html

AHOI2001是一种用于处理模式匹配和字符串搜索的经典算法,全称为"Another Happy Odyssey in 2001"。它通常应用于构建高效、空间优化的KMP(Knuth-Morris-Pratt)算法的一种改进版本。这种有限自动机常用于处理字符串搜索问题,尤其是在处理大量文本数据时。 关于题目代码的具体内容,这通常涉及到编程竞赛或算法实现题。通常,你需要编写一段程序,包括定义一个有限状态机(Finite Automaton),处理输入字符串和模式串,并根据AHOI2001算法来查找模式是否在原字符串中。关键部分会涉及如何创建前缀函数表、动态规划和自适应策略。 由于这不是一个直接的答案,下面是一个简化版的代码框架示例(假设用Python): ```python class AhoCorasickAutomaton: def __init__(self, patterns): self.prefix_func = self.build_prefix_function(patterns) def build_prefix_function(self, patterns): # 建立前缀函数表的计算过程... pass def search(self, text): index = 0 for pattern in patterns: while index < len(text) and index + len(pattern) <= len(text): if self.match(text[index:], pattern): return True index += self.prefix_func[pattern] return False def match(self, text, pattern): # 匹配函数,比较两个字符串是否相等... pass # 使用示例: patterns = ['AB', 'AC'] # 输入模式列表 automaton = AhoCorasickAutomaton(patterns) text = 'ABCABCD' # 待搜索的字符串 if automaton.search(text): print("Pattern found") else: print("Pattern not found")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值