Magic Numbers CodeForces - 628D
Magic Numbers CodeForces - 628D
dp函数中:pos表示当前处理到从前向后的第i位(从1开始编号),remain表示处理到当前位为止共产生了除以m的余数remain。
不一定要把a减一,也可以特判a自身,或者直接改记忆化搜索。
#include<cstdio>
#include<cstring>
#define md 1000000007
typedef long long LL;
LL m,d,ans1,ans2,len1;
LL ans[][][];
LL w[];
char c;
LL dp(LL pos,LL remain,bool pre0,bool limit)
{
if(pos>len1) return remain==&&pre0==;
if(!limit&&ans[pos][remain][pre0]!=-)
return ans[pos][remain][pre0];
LL i,res=,end=limit?w[pos]:;
for(i=;i<=end;i++)
if((pos%==&&i!=d)||(pos%==&&i==d))
res=(res+dp(pos+,(remain*+i)%m,pre0&&i==,limit&&i==w[pos]))%md;
return limit?res:(ans[pos][remain][pre0]=res);
}
int main()
{
LL i;
scanf("%I64d%I64d\n",&m,&d);
memset(ans,-,sizeof(ans));
scanf("%c",&c);
while(c!='\n')
{
w[++len1]=c-'';
scanf("%c",&c);
}
w[len1]--;
for(i=len1;i>=;i--)
{
if(w[i]>=) break;
w[i-]--;
w[i]+=;
}
ans1=dp(,,true,true);
memset(w,,sizeof(w));
len1=;
scanf("%c",&c);
while(c!='\n')
{
w[++len1]=c-'';
scanf("%c",&c);
}
ans2=dp(,,true,true);
printf("%I64d",(ans2-ans1+md)%md);
return ;
}
Magic Numbers CodeForces - 628D的更多相关文章
- Educational Codeforces Round 8 D. Magic Numbers 数位DP
D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the deci ...
- Codeforces CF#628 Education 8 D. Magic Numbers
D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 8 D. Magic Numbers
Magic Numbers 题意:给定长度不超过2000的a,b;问有多少个x(a<=x<=b)使得x的偶数位为d,奇数位不为d;且要是m的倍数,结果mod 1e9+7; 直接数位DP;前 ...
- CodeForces 628 D Magic Numbers 数位DP
Magic Numbers 题意: 题意比较难读:首先对于一个串来说, 如果他是d-串, 那么他的第偶数个字符都是是d,第奇数个字符都不是d. 然后求[L, R]里面的多少个数是d-串,且是m的倍数. ...
- Codeforces Round #189 (Div. 2) A. Magic Numbers【正难则反/给出一个数字串判断是否只由1,14和144组成】
A. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- URAL 1727. Znaika's Magic Numbers(数学 vector)
主题链接:http://acm.timus.ru/problem.aspx?space=1&num=1727 1727. Znaika's Magic Numbers Time limit: ...
- 【CF628D】Magic Numbers 数位DP
[CF628D]Magic Numbers 题意:求[a,b]中,偶数位的数字都是d,其余为数字都不是d,且能被m整除的数的个数(这里的偶数位是的是从高位往低位数的偶数位).$a,b<10^{2 ...
- Dima and Magic Guitar CodeForces - 366E
Dima and Magic Guitar CodeForces - 366E 题意: http://blog.csdn.net/u011026968/article/details/38716425 ...
- Codeforces 628D Magic Numbers
题意: 求在[a,b](a,b不含前导0)中的d−magic数中有多少个是m的倍数. 分析: 计数dp Let's call a number d-magic if digit d appears i ...
随机推荐
- homebrew -v 或homebrew -doctor报错请检查 .bash_profile是否有误
homebrew -doctor报错: /usr/local/Library/Homebrew/global.rb:109:in `split': invalid byte sequence in U ...
- 1987年国际C语言混乱代码大赛获奖的一行代码
macb() ? lpcbyu(&gbcq/_\021%ocq\012\0_=w(gbcq)/_dak._=}_ugb_[0q60)s+ 这是CoolShell博主之前做了一个非常有意思的在线 ...
- 文件宝局域网传输/播放功能使用帮助(Windows电脑用户)
使用局域网账户密码登录,可以访问电脑上所有文件 使用游客无账户密码登录,只能访问电脑上指定共享文件夹的文件. 1.怎么设置共享文件夹请参考: 方法1 1.在文件资源管理器中选择自己一个想共享的文件夹, ...
- hive增加Update、Delete支持
一.配置hive-site.xml二.建表三.操作四.总结 一.配置hive-site.xml CDH版本先进入Hive配置页 选择高级,找到hive-site.xml 的 Hive 客户端高级配置代 ...
- 文件读写&&内容替换
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- vue-router-h5-history
vue-router的HTML5 History 模式,这种模式充分利用 history.pushState API 来完成 URL 跳转而无须重新加载页面. const router = new V ...
- 常用: JS 获取浏览器窗口大小
// 获取窗口宽度 if (windows.innerWidth) winWidth = windows.innerWidth; else if ((document.body) && ...
- I.MX6 Android busybox 从哪里生成的
/**************************************************************************** * I.MX6 Android busybo ...
- POJ3304:Segments (几何:求一条直线与已知线段都有交点)
Given n segments in the two dimensional space, write a program, which determines if there exists a l ...
- exception.py
try: raise Exception except Exception as e: print(e) try: raise Exception('comment') except Exceptio ...