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 ;
}

最新文章

  1. 云计算之路-阿里云上:“黑色1秒”最新线索——w3tp与w3dt
  2. Eclipse启动时发生An internal error occurred during: &quot;Initializing Java Tooling&quot;.错误的解决方法
  3. Coursera台大机器学习课程笔记8 -- Linear Regression
  4. java web 实现验证码
  5. 【转】 Java虚拟机内存的堆区(heap),栈区(stack)和静态区(static/method)
  6. pragma指令简介
  7. VMware Workstation9安装Mac OS X10.9系统
  8. json的引号之伤
  9. android开发之-软件设置保存-快速学会使用SharedPreferences篇-实测
  10. Bash中的数学扩展
  11. [转]scrapy中的logging
  12. 【以2-SAT为主题的婚礼UVA11294】
  13. Educational Codeforces Round 61 Editorial--C. Painting the Fence
  14. wordcloud制作logo
  15. etcd raft如何实现leadership transfer
  16. MongoDB的增删查改基本操作
  17. nodejs通过request请求远程url的文件并下载到本地
  18. Gym.102059: 2018-2019 XIX Open Cup, Grand Prix of Korea(寒假gym自训第一场)
  19. flask框架1
  20. php端口号设置和查看

热门文章

  1. hdu5399Too Simple
  2. Java基础实例
  3. 【Mongodb教程 第四课 】MongoDB 创建集合
  4. 基于 Vue.js 之 iView UI 框架非工程化实践记要 使用 Newtonsoft.Json 操作 JSON 字符串 基于.net core实现项目自动编译、并生成nuget包 webpack + vue 在dev和production模式下的小小区别 这样入门asp.net core 之 静态文件 这样入门asp.net core,如何
  5. 【git体验】git原理及基础
  6. 轻量级批量Omnitty工具安装和简单使用
  7. WEB服务器安装oracle jdbc
  8. Android调用本地WebService
  9. 聚合类新闻client初体验
  10. ubuntu截图工具及GNOME的使用及类似qq截图快捷键