CF 477 C Dreamoon and Strings (DP)
来源:互联网 发布:龙珠超 知乎 编辑:程序博客网 时间:2024/06/05 04:26
题目: LINK
dp[i][j] 表示前i个字母里面去除j个字母后最多的不重复的p串的数量.
有两种情况,要么选取1~i中最后一个和p一样的串,要么不选取,dp[i][j] = max(dp[i-1][j], dp[ii][jj]+1), ii为匹配完p后在原串中的位置,jj为j-(匹配p过程中删去字母的数量);
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <string>#include <vector>#include <cmath>#include <queue>#include <map>#include <set>using namespace std; #define INF 1000000000//typedef __int64 LL; #define N 2011#define M 511char str1[N], str2[N]; int dp[N][N]; int main() {#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin); #endif // ONLINE_JUDGEscanf("%s%s", str1+1, str2+1); int len1 = strlen(str1+1); int len2 = strlen(str2+1); for(int i = 1; i <= len1; i ++) {int ii = i, jj = len2; while(ii >= 1 && jj >= 1 ) {if(str1[ii] == str2[jj]) jj--; ii --; }if(jj == 0) {int dif = i - ii - len2; for(int th = 0; th <= ii; th ++) {dp[i][dif + th] = dp[ii][th] + 1; }}for(int th = 0; th < i; th ++) {dp[i][th] = max(dp[i][th], dp[i-1][th]); }}for(int i = 0; i <= len1; i ++) {printf("%d ", dp[len1][i]); }return 0; }
0 0
- CF 477 C Dreamoon and Strings (DP)
- 【codeforces】477C Dreamoon and Strings dp
- 477 C. Dreamoon and Strings
- 【Codeforces】 477C Dreamoon and Strings
- Dreamoon and Strings - CodeForces #272 (Div. 1) C dp
- 【CODEFORCES】 C. Dreamoon and Strings
- CF 476C Dreamoon and Sums[数学]
- E. Dreamoon and Strings(Codeforces Round #272)
- Codeforces 476 E. Dreamoon and Strings
- E. Dreamoon and Strings(Codeforces Round #272)
- CF 272B Dreamoon and WiFi
- Codeforces 360C Levko and Strings (dp)
- Codeforces 360C Levko and Strings dp
- 【CF】 467C George and Job DP
- CF 467C DP George and Job
- 477 D. Dreamoon and Binary
- 477 B. Dreamoon and Sets
- 477 A. Dreamoon and Sums
- 新手建站千万不能有的三种心态
- UVa 156 Ananagrams
- Target runtime Apache Tomcat v7.0 is not defined.
- python学习旅程笔记3-控制流
- 网易有道CEO周枫:在线教育的冰山
- CF 477 C Dreamoon and Strings (DP)
- jpa注解
- POI读取Excel(兼容Excel2003、Excel2007)
- MYSQL手动备份和还原
- android anr traces日志分析方法
- MyISAM InnoDB 区别
- office 2013 打开后操作异常
- linux 编辑文件,与修改文件名
- 详细介绍Java垃圾回收机制