hdu 4295 4 substrings problem
来源:互联网 发布:php换行代码br不生效 编辑:程序博客网 时间:2024/06/05 10:22
4 substrings problem
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 442 Accepted Submission(s): 148
Problem Description
One day you heard the following joke
In America, you write strings.
In Soviet Russia, String writes YOU!! 1
And find that now string is writting you! So to get rid of it, you must solve the following problem:
Given a string S and its four substring a,b,c, and d. In a configuration, you can place four substrings exactly one position it occurs in S (they may overlap), and characters covered by at least one such substring is called “covered”.
You should solve for minimum and maximum possible number of covered characters in a configuration.
You may assume that s contains only lowercase letters, and is of length less than 4096. However, lengths of a,b,c, and d would never exceed 64.
-------------------------------------------------------------------
1An infamous Russian reversal
In America, you write strings.
In Soviet Russia, String writes YOU!! 1
And find that now string is writting you! So to get rid of it, you must solve the following problem:
Given a string S and its four substring a,b,c, and d. In a configuration, you can place four substrings exactly one position it occurs in S (they may overlap), and characters covered by at least one such substring is called “covered”.
You should solve for minimum and maximum possible number of covered characters in a configuration.
You may assume that s contains only lowercase letters, and is of length less than 4096. However, lengths of a,b,c, and d would never exceed 64.
-------------------------------------------------------------------
1An infamous Russian reversal
Input
There are several test cases.
For each test case there are 5 lines, denoting S,a,b,c, and d, respectively.
Please process until the EOF (End Of File).
For each test case there are 5 lines, denoting S,a,b,c, and d, respectively.
Please process until the EOF (End Of File).
Output
For each test case, please print a single line with two integers, first the minimum, then the maximum.
Sample Input
hellohelloabacabaabbaac
Sample Output
4 54 6
Source
2012 ACM/ICPC Asia Regional Chengdu Online
代码:(比较低效)
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=4100;char s[N],ss[70];short l,sl[4],maxl;short flag[N],d1[N][16][65],d2[N][16][65];int main(){int i,j,k,x;while(~scanf("%s",s)){l=strlen(s);memset(flag,0,sizeof(flag[0])*l);for(i=0;i<4;i++){scanf("%s",ss);sl[i]=strlen(ss);for(j=0;j+sl[i]<=l;j++){for(k=0;ss[k];k++)if(s[j+k]!=ss[k])break;if(ss[k]=='\0') flag[j]|=1<<i;}if(sl[i]>maxl) maxl=sl[i];}memset(d1,0x3f,sizeof(d1[0])*(l+1));memset(d2,0xc3,sizeof(d1[0])*(l+1));d1[0][0][0]=d2[0][0][0]=0;for(i=0;i<l;i++)for(j=0;j<16;j++)for(k=0;k<=maxl;k++){d1[i+1][j][k?k-1:0]=min(d1[i][j][k],d1[i+1][j][k?k-1:0]);d2[i+1][j][k?k-1:0]=max(d2[i][j][k],d2[i+1][j][k?k-1:0]);for(x=0;x<4;x++){if((1<<x&~j)&&(1<<x&flag[i])){short t=max((short)k,sl[x]);d1[i][1<<x|j][t]=min((short)(d1[i][j][k]+t-k),d1[i][1<<x|j][t]); d2[i][1<<x|j][t]=max((short)(d2[i][j][k]+t-k),d2[i][1<<x|j][t]);}}}printf("%hd %hd\n",d1[l][15][0],d2[l][15][0]);}return 0;}
- hdu 4295 4 substrings problem
- HDU 4295 4 substrings problem(状态压缩)
- hdu 4295 4 substrings problem DP 字符串
- hdu4295 4 substrings problem 状压dp
- Substrings hdu
- HDU Substrings
- Substrings HDU
- HDU:Substrings
- Substrings HDU
- ZOJ Problem 1374 Substrings
- hdu-1238 Substrings
- HDU 1238 Substrings
- HDU 1238 ( Substrings )
- Hdu 1238 Substrings
- hdu 1238 Substrings
- hdu 4455 Substrings
- hdu 1238 Substrings
- HDU 1238 Substrings
- Windows下重叠I/O模型
- Humble Numbers
- LeetCode: Jump Game
- 各种嵌入式根文件系统制作
- ATPCS
- hdu 4295 4 substrings problem
- ubuntu 软件 优化 美化 桌面 浏览器 词典
- 随机森林
- hdu 1874 畅通工程续
- LayoutInflater作用及使用
- Python线程指南
- web服务器的实现
- 恢复之还原归档重做日志
- tcp实现回射服务器