gym101628 problemA Arthur's Language 递推DP
来源:互联网 发布:永创科技电脑淘宝 编辑:程序博客网 时间:2024/05/16 19:12
http://codeforces.com/gym/101628/problem/A
题意 给出两个串 a b
问有多少种方法使得 a删除一些字母后变成b串
解题思路:
一开始以为是组合数取模啥的,后来想一想,可以用DP写 因为每一个字母的状态只与他前一个字母的状态有关,这样的话就很好写了。
dp[i][j] 表示 前i个字符 构成b字符串前j个字母的方案数。
后来想一想,第一维其实是可以省掉的, 相当于滚动数组。
#include<iostream>#include<set>#include<queue>#include<vector>#include<algorithm>#include<cstdio>#include<iomanip>#include<map>#include<string>#include<cstring>#define lson l,m,rt<<1#define rson m+1,r,rt<<1using namespace std;vector<int> V[10];const int MAX=1e5+10;string str;char ch[14];vector<int> id[222];long long dp[11];const int MOD=1e9+7;int main(){ cin>>str; scanf("%s",ch+1); int len=strlen(ch+1); memset(id,-1,sizeof id); for(int i=1;i<=len;i++){ id[ch[i]].push_back(i); } dp[0]=1; int len2=str.length(); str='0'+str; for(int i=1;i<=len2;i++){ int cnt; for(int j=id[str[i]].size()-1;j>=0;j--){ cnt=id[str[i]][j]; dp[cnt]+=dp[cnt-1]; dp[cnt]%=MOD; } } cout<<dp[len]%MOD<<endl;}
阅读全文
0 0
- gym101628 problemA Arthur's Language 递推DP
- POJ-3682King Arthur's Birthday Celebration(概率DP)
- POJ 3682 King Arthur's Birthday Celebration 概率DP
- POJ 3682 King Arthur's Birthday Celebration (概率DP)
- problema
- problemA
- ZOJ 3141 Arnie's Dog Biscuits【dp递推】
- hdu4337 King Arthur's Knights
- hdu4337 King Arthur's Knights
- hdu1438 dp递推
- poj3786(DP,递推)
- hdu4489 dp+递推
- hdu5375 dp+递推
- hdu5286 dp+递推
- 期望dp递推
- 【dp】递推 zoj3747
- HDU 4489The King’s Ups and Downs(dp递推)
- HDU 4489The King’s Ups and Downs(dp递推)
- 以太坊创建多重签名钱包以及应用
- 第七届蓝桥杯JAVA B组省赛第四题
- swoole进程通讯2:队列
- 00.openssl key generation
- 深度增强学习入门笔记(二)
- gym101628 problemA Arthur's Language 递推DP
- 一些工作回顾与规划
- Mysql集群和一主多从之后如何分库分表的路由规则详解(四)
- What is Split Brain in Oracle Clusterware and Real Application Cluster (文档 ID 1425586.1)
- qml程序主窗体自制关闭按钮
- 训练日记
- Python 从入门到实践 8-1 课后习题
- classpath和classpath*区别
- python工具代码之身份证校验持续更新:【内向即失败--王奕君】