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. mysql手记

    myisam innoDB是mysql经常使用的存储引擎 MyISAM不支持事务.也不支持外键.但其訪问速度快.对事务完整性没有要求. InnoDB存储引擎提供了具有提交.回滚和崩溃恢复能力的事务安全 ...

  2. hdu 5087 Revenge of LIS II ( LIS ,第二长子序列)

    链接:hdu 5087 题意:求第二大的最长升序子序列 分析:这里的第二大指的是,全部的递增子序列的长度(包含相等的), 从大到小排序后.排在第二的长度 cid=546" style=&qu ...

  3. 手把手教你_怎么找android应用的包名和启动activity

    自己主动化測试中常常遇到这个问题,关于这个题目,方法众多,咱的目的是找个比較简单靠谱的: 方法一: 先进入cmd窗体,adb shell 后: cd /data/data ls 能够看到包名了吧,缺点 ...

  4. iOS项目开发实战——plist数组解析

    plist数据是苹果公司创造的数据格式,基于XML,因为在iOS,Mac系统中操作plist很方便,所以我们经常会用到.在iOS项目中.系统会自己主动生成一个Info.plist文件,里面存放了iOS ...

  5. C# MVC 枚举转 SelectListItem

    <span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif; background-color: r ...

  6. 65*24=1560<2175 对数据的统计支撑决策假设 历史数据正确的情况下,去安排今后的任务

    没有达到目标,原因不是时间投入不够,而是不用数据决策,不用数据调度定时脚本 [数据源情况统计]----># 近30天,日生效coin数目SELECT COUNT(DISTINCT coin) A ...

  7. 代理ip proxy

    import requestsimport timefrom selenium import webdriverfrom selenium.webdriver.chrome.options impor ...

  8. Get started with Sourcetree

    Understand the interface Bookmarks window From that window, select the Local or Remote buttons to vi ...

  9. bzoj 5017 炸弹

    题目大意: 直线上有n个炸弹有坐标x和半径r 当一个炸弹被引爆时 若有炸弹的坐标在该炸弹坐标+-r范围内则另一个炸弹也被引爆 求先引爆每一个炸弹最终会引爆多少炸弹 思路: 可以想到n平方连边然后tar ...

  10. BZOJ_3448_[Usaco2014 Feb]Auto-complete_Trie树

    BZOJ_3448_[Usaco2014 Feb]Auto-complete_Trie Description Bessie the cow has a new cell phone and enjo ...