http://codeforces.com/contest/766/problem/C

关键在于dp,如何计数。

设dp[i]表示前i个字母中,能分成多少份合法的情况。那么答案就是dp[n],其中dp[0] = 1;

比如说:aab的,也就是样例。

对于每一个i,枚举其往后能组合成那个,比如b,能组合成b,也就是自己一个,或者ab,但是不能aab,因为违反了条件。

那么,组合成b的时候,就应该加上dp[2]的值,也就是前2个分成的合法情况有多少种,b作为单独一个插去后面。

ab同理。

dp[1] = 1,也就是只有a,

dp[2] = 2,有a/a  和 aa

dp[3] = 3,有a/a/b、aa/b和a/ab

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset> const int MOD = 1e9 + ;
const int maxn = 1e3 + ;
int cnt[maxn][ + ];
char str[maxn];
int a[maxn];
int dp[maxn];
bool check(int last, int pre) {
for (int i = ; i <= ; ++i) {
if (cnt[last][i] - cnt[pre - ][i] != && last - pre + > a[i]) return false;
}
return true;
}
void work() {
int n;
cin >> n;
cin >> str + ;
for (int i = ; i <= ; ++i) cin >> a[i];
for (int i = ; i <= n; ++i) {
for (int j = ; j <= ; ++j) {
if (str[i] - 'a' + == j) {
cnt[i][j] = cnt[i - ][j] + ;
} else cnt[i][j] = cnt[i - ][j];
}
}
int ansone = , anstwo = -inf;
for (int i = ; i <= n; ++i) {
for (int j = i; j >= ; --j) {
if (check(i, j)) {
anstwo = max(anstwo, i - j + );
} else break;
}
}
int ansthree = ;
int pre = ;
for (int i = ; i <= n; ++i) {
if (check(i, pre) == false) {
ansthree++;
pre = i;
}
}
dp[] = ;
for (int i = ; i <= n; ++i) {
for (int j = i; j >= ; --j) {
if (!check(i, j)) break;
dp[i] += dp[j - ];
dp[i] %= MOD;
}
}
// for (int i = 1; i <= n; ++i) {
// cout << dp[i] << endl;
// ansone += dp[i];
// ansone %= MOD;
// }
// ansone = (ansone + MOD - n + 1) % MOD;
cout << dp[n] << endl;
cout << anstwo << endl;
cout << ansthree << endl;
}
int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
IOS;
work();
return ;
}

C. Mahmoud and a Message dp + 暴力的更多相关文章

  1. Codeforces Round #396 (Div. 2) C. Mahmoud and a Message dp

    C. Mahmoud and a Message 题目连接: http://codeforces.com/contest/766/problem/C Description Mahmoud wrote ...

  2. Codeforces 766C - Mahmoud and a Message

    C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. Codeforces 766C Mahmoud and a Message 2017-02-21 13:57 62人阅读 评论(0) 收藏

    C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  4. Codeforces Round #396 (Div. 2) C. Mahmoud and a Message

    地址:http://codeforces.com/contest/766/problem/C 题目: C. Mahmoud and a Message time limit per test 2 se ...

  5. 【codeforces 766C】Mahmoud and a Message

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. Codeforces 766C:Mahmoud and a Message(DP)

    题目链接:http://codeforces.com/problemset/problem/766/C 题意 有一个长度为n的字符串,第二行有26个数字,位置1~26对应为a~z的字母,数值表示该字母 ...

  7. codeforces 766 C. Mahmoud and a Message(简单dp)

    题目链接:http://codeforces.com/contest/766/problem/C 题意:给你一个长度为n的字符串,这个字符串只包含小写字母,然后让你把这个字符串进行分割,形成若干个小的 ...

  8. POJ 2029 DP || 暴力

    在大矩形中找一个小矩形 使小矩形包括的*最多 暴力或者DP  水题 暴力: #include "stdio.h" #include "string.h" int ...

  9. 区间Dp 暴力枚举+动态规划 Hdu1081

    F - 最大子矩形 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Status Des ...

随机推荐

  1. Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的使用方法总结

    具体解读Jquery各Ajax函数: $.get(),$.post(),$.ajax(),$.getJSON() 一 $.get(url,[data],[callback]) 说明:url为请求地 ...

  2. Android使用am命令实现拨打电话、打开应用

    前提: 在Android 通话自己主动化測试中会用到am命令去拨打电话.打开音乐播放器播放音乐等等操作. 这里总结一下am命令. Android am命令: (1)命令參数: am start -n ...

  3. 【剑指Offer面试题】 九度OJ1517:链表中倒数第k个结点

    鲁棒性是指程序可以推断输入是否符合规范要求,并对不和要求的输入予以 合理的处理. 题目链接地址: http://ac.jobdu.com/problem.php?pid=1517 题目1517:链表中 ...

  4. windows下Python扩展问题error: Unable to find vcvarsall.bat

    由于对于Windows下Python扩展不熟,今天遇到一个安装问题,特此做个tag.解决方式在stackoverflow上,网址例如以下: http://stackoverflow.com/quest ...

  5. 命令行方式下登录SqlPlus,密码含特殊字符

    全撞上了! 真难侍候!oracle 12c,想登录sql plus,结果没有图形界面,直接出来个命令行.这下好了,我这个数据库,多实例,意味着登录要指定实例:密码中含有特殊字符"@" ...

  6. 并不对劲的bzoj1861: [Zjoi2006]Book 书架

    传送门-> 这题的正确做法是splay维护这摞书. 但是并不对劲的人选择了暴力(皮这一下很开心). #include<algorithm> #include<cmath> ...

  7. Java语法基础练习2

    ---恢复内容开始--- 1.仔细阅读示例:EnumTest.java分析结果 代码: 运行结果: 分析:枚举类型就是一个类,枚举中的常量就是枚举类型中的实例,可把字符串转化为枚举:而且他本身是一个类 ...

  8. python requests 调用restful api

    #!/usr/bin/python# -*- coding: utf-8 -*- import jsonimport requestsfrom urlparse import urljoin BASE ...

  9. SimpliciTI 地址分配

    1.多个ED节点和AP正确连接后,AP都会给ED分配一个相应的地址.当某个ED出现意外,比如电源问题,和AP断开连接,AP并不将该ED节点的地址消除.当该ED恢复正常,重新申请加入网络时,AP会检测该 ...

  10. C++中continue

    /* C++中continue使用 Author:盗了一个你 */ #include<iostream> using namespace std; int main() { int val ...