codeforces 645e
来源:互联网 发布:数据建模师 编辑:程序博客网 时间:2024/06/04 19:53
题意:在原字符串加上n个字符(1e6) 使得他的不同子串数量最多 字符范围为k
思路:先考虑放一个字符 会有生成多少个新字串 ,那么我们来统计现在如果包含这个字符的子串,由于这个字符是放在最后的,所以,字串增加数量就是*2,但是有重复的部分没有减去,那么什么字串会重复呢? 由于是最后一个字符,所以重复的肯定是上次出现字符放到最后以后形成的所有子串,那么减去这个数,就可以得出新加了多少串。
然后我们考虑到底加那个字符增加最多?那应该是减去最少的 就是增加最多的。
#include<stdio.h>#include<string.h>#include<vector>#include<algorithm>#include<queue>#include<math.h>#include<string>using namespace std;#define LL long long#define MOD 1000000007#define N 10000010LL sum[30];int n,m;char ch[N];int pos[30];int main(){ scanf("%d%d%s",&n,&m,ch); LL ans=1; for(int i=0;ch[i];i++) { int temp=ch[i]-'a'; LL pre=ans; ans=((ans*2-sum[temp])%MOD+MOD)%MOD; sum[temp]=pre; pos[temp]=i+1; } int nx=strlen(ch); for(int i=0;i<n;i++) { int x=N,y=0; for(int j=0;j<m;j++) { if(pos[j]<x) { x=pos[j]; y=j; } } LL pre=ans; ans=((ans*2-sum[y])%MOD+MOD)%MOD; sum[y]=pre; pos[y]=i+1+nx; } printf("%lld\n",ans); return 0;}
0 0
- codeforces 645e
- Codeforces 645E (构造 DP)
- Codeforces 645E Intellectual Inquiry (贪心+DP)
- Codeforces 645E Intellectual Inquiry [贪心] [DP]
- 【Codeforces 645E】【贪心】Intellectual Inquiry
- codeforces 163E e-Government
- 【Codeforces 163E】E-Government
- Codeforces 78E Evacuation
- 【dp】codeforces 83E
- Codeforces 124 E
- Codeforces 231E
- Codeforces 231E - Cactus
- Codeforces #163 Div2 E
- codeForces 35E
- Codeforces 35E
- Playlist codeforces 268E
- Codeforces 148E(Porcelain)
- codeforces round#177 E
- C#中string和stringBuilder的最大区别
- input设置键盘监听事件
- QML OpenGL
- 购物抛物线
- 使用fuel部署openstack时遇到的问题记录一下
- codeforces 645e
- UI元素状态伪类选择器
- RecyclerView 下拉刷新上拉加载更多
- 获取spring的ApplicationContext几种方式
- 用URL来操作Hadoop
- 数据库面试题
- 只要是搜索引擎能回答的就别问别人……
- 根据label的文字判断高度
- Linux c日志打印