HihoCoder 1033交错和(数位DP第三题)
2017-11-03 11:07
337 查看
(写挂了,有空再补)
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
f(x) = a0 - a1 + a2 - ... + ( - 1)n - 1an - 1
例如:
f(3214567) = 3 - 2 + 1 - 4 + 5 - 6 + 7 = 4
给定
View Code
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
给定一个数 x,设它十进制展从高位到低位上的数位依次是 a0, a1, ..., an - 1,定义交错和函数:f(x) = a0 - a1 + a2 - ... + ( - 1)n - 1an - 1
例如:
f(3214567) = 3 - 2 + 1 - 4 + 5 - 6 + 7 = 4
给定
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<memory> #include<cstring> #include<cmath> using namespace std; #define LL long long const LL Mod=1000000007; LL a[20],cnt,L,R,S; LL ans,dp[20][400][2][2][2]; LL dfs(LL pos,LL sum,LL limit,LL sign,LL fir,LL sub) { if(pos==0) return sum==S?sub:0; if(!limit&&sign&&dp[pos][S-sum+200][1][1][1]) { for(int i=1;i<=pos;i++) sub=sub*10%Mod; sub=(sub+dp[pos][S-sum+200][1][1][1])%Mod; return sub; } LL Up=limit?a[pos]:9; LL tmp=0; for(LL i=0;i<=Up;i++){ if(fir&&i==0) continue; tmp=(tmp%Mod+dfs(pos-1,sum+(sign?1:-1)*i,limit&&i==Up,1-sign,0,sub*10%Mod+i))%Mod; } dp[pos][sum][limit][sign][fir]=tmp; return tmp; } LL cal(int v) { cnt=0;ans=0; while(v){ a[++cnt]=v%10; v/=10; } for(LL i=1;i<=cnt;i++){ LL tmp=dfs(i,200,i==cnt,1,1,0);//枚举第一位 ,避开前导0 ans+=tmp; } return ans; } int main() { scanf("%lld%lld%lld",&L,&R,&S); S+=200; printf("%lld",(cal(R)-cal(L-1)+Mod)%Mod); return 0; }
View Code
相关文章推荐
- 【数位dp 求满足的值和】hihocoder 1033 交错和
- hihocoder1033-数位dp&数位求和&好题-交错和
- 【HIHOCODER 1033 】 交错和(数位DP)
- hihocoder 1033 交错和 (数位dp)
- hihocoder 1033 交错和 数位DP
- hihoCoder 1033 : 交错和 数位dp
- 数位DP 浅谈(hihocoder 1033:交错和)
- 数位DP 浅谈(hihocoder 1033:交错和)
- [数位dp] hihoCoder 1033 交错和
- 数位DP 浅谈(hihocoder 1033:交错和)
- hihocoder1033(数位dp)
- [hihocoder 1033]交错和 数位dp/记忆化搜索
- hihoCoder 交错和 (数位DP)
- hiho 1033 —— 交错和 【数位DP】
- hihoCoder #1033 : 交错和 [ 数位dp ]
- hihocoder #1033 : 交错和 (数位dp)
- HiHoCoder1033交错和——数位dp
- hihoCoder 1259 A Math Problem(数位dp)
- HihoCoder 1033:交错和
- hihoCoder 1301 筑地市场 数位dp加二分答案