hdu 3886 - Final Kichiku “Lanlanshu”(数位dp)多校联合
来源:互联网 发布:北航软件学院研究生院 编辑:程序博客网 时间:2024/06/08 17:37
Final Kichiku “Lanlanshu”
Problem Description
During 2010 summer training, temperlisyer often does problem like this:
“Consider a decimal integer as sequence of digits {D0, D1 … Dn-1} (D0 > 0), if exists such x, y and z, satisfying:
Di−1<Di(0<i<=x) Di−1=Di(x<i<=y) Di−1<Di(y<i<=z) Di−1>Di(z<i<=n−1)
We call this integer “Lanlanshu”, now give you two numbers A and B, calculate how many “Lanlanshu” are in [A, B].“
He solved so many of these and finally get bored, and then get crazy! He decided to make up a problem to put this type of problems to an end.
Give you a string str consists only by ‘/’, ‘-‘ and ‘\’, and its length is l. Consider a decimal integer as sequence of digits {D0, D1 … Dn-1} (D0 > 0), define x0=0, xl=n-1, if exists such x1, x2…xl (x0 < x1 < x2 < … < xl) satisfying:
1. If str[i]=’/’,
2. If str[i]=’-’,
3. If str[i]=’\’,
We call it Final Kichiku “Lanlanshu”, now give you two numbers A and B, calculate how many Final Kichiku “Lanlanshu” are in [A, B]. This number maybe huge, we only want to now the last 8 digits of the result.
Input
Multiple cases (no more than 100), for each case:
The first line is string str, length is below 100.
The second line contains two integers A and B (0≤Ai≤Bi≤10^100).
Input terminates by EOF.
Output
For each case, output 8 digits representing the last 8 digits of the number of Final Kichiku “Lanlanshu” in [A, B]. If it’s less than 8 digits, fill it with leading zeros.
Sample Input
/\
01221 2012
Sample Output
00000315
Author
temperlsyer
Source
2011 Multi-University Training Contest 5 - Host by BNU
题意: A,B之间有多少个数,满足给定字符串的趋势
思路:dp[cur][pos][last]表示处理到当前为止,满足趋势字符串到pos位置,上一位是last的有多少个
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<stack>#include<map>#include<set>#include<algorithm>using namespace std;const int MOD=1e8;const int maxn=10;string A,B;string st;int stlen,alen;int dp[110][110][10];int dig[110];string subone(string A){ int len=A.size(); if(A[len-1]>'0') { A[len-1]-=1; return A; } else { int i=len-1; while(i>=0&&A[i]<='0')A[i]='9',i--; A[i]-=1; return A; }}int check(int x,int y,char op){ if(op=='/')return x<y; if(op=='-')return x==y; return x>y;}int dfs(int cur,int e,int z,int pos,int last){ if(cur==alen)return pos==stlen; if(!e&&!z&&dp[cur][pos][last]!=-1) return dp[cur][pos][last]; int end=e?dig[cur]:9; int ans=0; for(int i=0;i<=end;i++) { if(z)ans+=dfs(cur+1,e&&i==end,z&&i==0,0,i); else { if(pos<stlen&&check(last,i,st[pos])) ans+=dfs(cur+1,e&&i==end,0,pos+1,i); else if(pos>0&&check(last,i,st[pos-1])) ans+=dfs(cur+1,e&&i==end,0,pos,i); } ans%=MOD; } if(!e&&!z)dp[cur][pos][last]=ans; return ans;}int solve(string a){ memset(dp,-1,sizeof(dp)); int len=a.size(); alen=a.size(); int st=0; while(a[st]=='0')st++; for(int i=st;i<len;i++)dig[i]=a[i]-'0'; return dfs(st,1,1,0,0);}int main(){ while(cin>>st) { cin>>A>>B; stlen=st.size(); int len=A.size(); A=subone(A); printf("%08d\n",(solve(B)-solve(A)+MOD)%MOD); } return 0;}
- hdu 3886 - Final Kichiku “Lanlanshu”(数位dp)多校联合
- HDU 3886 Final Kichiku “Lanlanshu” 数位DP
- hdu 3886 Final Kichiku “Lanlanshu” (数位dp)
- [数位dp] hdu 3886 Final Kichiku “Lanlanshu”
- HDU 3886 Final Kichiku “Lanlanshu” 数位DP
- 【HDU】3886 Final Kichiku “Lanlanshu” 数位DP
- hdu 3886 Final Kichiku “Lanlanshu(数位DP进阶)
- hdu_3886_Final Kichiku “Lanlanshu”(数位DP)
- Final Kichiku “Lanlanshu”
- hdu 4352 - XHXJ's LIS (数位dp)多校联合
- HDU 3886 数位DP
- HDU-3886-数位dp
- hdu 4734(数位dp)
- HDU 5456(数位dp)
- HDU Bomb(数位DP)
- hdu 2089(数位DP)
- HDU 2089(数位DP)
- HDU 2089 (数位dp)
- ZeroMQ_官方文档C#示例
- Android-AppWidget
- V$LOCK视图的介绍和使用
- 从GDI到Direct2D:贴图
- Android屏幕图标尺寸规范
- hdu 3886 - Final Kichiku “Lanlanshu”(数位dp)多校联合
- Python - sqlalchemy Orm
- CSS规范 - 典型错误
- Android-自定义Launcher基本思想
- CSS规范 - 最佳实践
- LoadRunner的安装以及无法调用ie的解决方案
- JavaBean 用反射自己实现简单内省操作 基础
- CSS规范 - 优化方案
- mysql 数据库字段为 call 数据无法插入