ssoj2424: 编码hard(dp)
来源:互联网 发布:淘宝怎么看下单顺序 编辑:程序博客网 时间:2024/04/29 06:18
题意:给一串数字,可以表示成多少个a(个数)个b(0~9)(内容);
思路:f[ i ]表示以i为末尾内容有多少种。f[ i ]=Σf[ j ](j=2~i-2)且s[ i ]!=s[ j ] && s[ j+1 ]!='0';前缀和,删掉不合法的。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <cctype>using namespace std;const int maxn=1000006;const int mod=998244353;char s[maxn];int n,f[maxn],sum=0,del[maxn];int main(){ scanf("%s",s+1); n=strlen(s+1); memset(del,0,sizeof(del)); if(s[1]=='0'){printf("0\n");return 0;} else{sum=0; for(int i=2;i<=n;++i){s[i]-=48;f[i]=(sum-del[s[i]]+1+mod)%mod;if(s[i]!=0){ sum=(sum+f[i-1])%mod; del[s[i-1]]=(del[s[i-1]]+f[i-1])%mod;} } }printf("%d\n",f[n]); return 0;}
0 0
- ssoj2424: 编码hard(dp)
- hdu4363 Draw and paint(hard DP )
- Codeforces 706C Hard problem (DP)
- CodeForces 706 C. Hard problem(dp)
- CF#367(Div2)C. Hard problem (DP)
- Topcoder SRM 663 Div2 Hard: CheeseRolling(状压DP)
- Codeforces Round #367 (Div. 2) C. Hard problem (DP)
- Codeforces Round #367 (Div. 2) C. Hard problem (dp)
- Codeforces Round #367 (Div. 2) C Hard problem(DP)
- Codeforces Round #367 (Div. 2) C. Hard problem (dp)
- Codeforces Round #367 (Div. 2) C. Hard problem(dp)
- codefoces 706C Hard problem (dp/dfs)
- Codeforces #367(Div.2)C.Hard problem【dp】
- Codeforces Round #367 (Div. 2) C. Hard problem (DP)
- Codeforces Round #367 (Div. 2) C Hard problem(dp)
- SRM675 div2 hard TreeAndPathLength2(DP)
- codeforces 285E Positions in Permutations(DP+容斥,hard)
- DP——Hard problem (Codeforces Round #367 (Div. 2) C)
- 剑指Offer-3-二维数组中的查找
- 一切从头开始
- 把Fortran代码自动转为C++代码
- 软件开发-Struts基础与案例开发详解
- Struts2标签-UI标签
- ssoj2424: 编码hard(dp)
- 1656:Counting Black
- C语法基础
- Java程序员应具备的技能
- 基于tomcat运行HTML5 WebSocket echo例子
- 利用html5调用本地摄像头拍照上传图片
- Java用GZIP进行简单压缩
- 剑指Offer-4-替换空格
- test8.2