gym101628 problemA Arthur's Language 递推DP

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<<1
using 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值