Educational Codeforces Round 8 D. Magic Numbers
题意:给定长度不超过2000的a,b;问有多少个x(a<=x<=b)使得x的偶数位为d,奇数位不为d;且要是m的倍数,结果mod 1e9+7;
直接数位DP;前两维的大小就是mod m的大小,注意在判断是否f[pos][mod] != -1之前,要判断是否为边界,否则会出现重复计算;
- #include<bits/stdc++.h>
- using namespace std;
- #define inf 0x3f3f3f3f
- #define MS1(a) memset(a,-1,sizeof(a))
- const int N = ,MOD = 1e9+;
- char a[N],b[N];
- int f[N][N][],n,m,d;
- int dfs(char* s,int p,int mod,int on = )
- {
- if(p == n) return mod == ;
- int& ans = f[p][mod][on];
- if(ans != -) return ans;
- ans = ;
- for(int i = ;i <= (on?s[p] - '':);i++){
- if(p% && i != d) continue;
- if(p% == && i == d) continue;
- (ans += dfs(s,p+,(mod*+i)%m,on && i == s[p] - '')) %= MOD;
- }
- return ans;
- }
- int calc(char* s)
- {
- MS1(f);
- return dfs(s,,);
- }
- int main()
- {
- scanf("%d%d",&m,&d);
- scanf("%s%s",a,b);
- n = strlen(a);
- for(int i = n-;i >= ;i--){ // a - 1;
- if(a[i] == '') a[i] = '';
- else{a[i]--;break;}
- }
- printf("%d",(calc(b)-calc(a)+MOD)%MOD);
- }
Educational Codeforces Round 8 D. Magic Numbers的更多相关文章
- Educational Codeforces Round 8 D. Magic Numbers 数位DP
D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the deci ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- Educational Codeforces Round 9 F. Magic Matrix 最小生成树
F. Magic Matrix 题目连接: http://www.codeforces.com/contest/632/problem/F Description You're given a mat ...
- Educational Codeforces Round 2 A. Extract Numbers
打开题目链接 题意:输入一个字符串,用,或:分隔输出字符串和整数(不含前导0和浮点数) ACcode: #include <iostream> #include <cstdio> ...
- Educational Codeforces Round 60 D. Magic Gems
易得递推式为f[i]=f[i-1]+f[i-M] 最终答案即为f[N]. 由于N很大,用矩阵快速幂求解. code: #include<bits/stdc++.h> using names ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
随机推荐
- python--while循环
1.最简单的while True循环 count = while True : : print('hello',count) break count += hello 2.利用while循环写一个猜年 ...
- CSS——选择器
css选择器 css选择器可分为:标签(元素)选择器,ID选择器,类选择器,属性选择器,后代选择器,子代选择器,相邻兄弟选择器和兄弟选择器.... 标签选择器: //E{attr:value;attr ...
- Android_Dialog
layout.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...
- Fortify规则与CERT JAVA 安全编程规范的对照表
Fortify规则与CERT JAVA 安全编程规范的对照表http://www.automationqa.com/forum.php?mod=viewthread&tid=4353& ...
- [原]unity中WWW isDone方法只能在主线程中调用
项目中要使用动态加载,原计划是生成WWW对象后,放到一个容器里.由一个独立线程轮询容器里的对象,如果www.isDone为true时,回调一个接口把结果交给请求方. new Thread( new T ...
- mstsc 终端服务器超出了最大允许连接的解决办法
终端服务器超出了最大允许连接的解决办法 win7系统:运行,输入mstsc /v xxx.xxx.xxx.xxx /admin win2003系统:运行,输入mstsc /v xxx.xxx.xx ...
- 多个DIV让float:left属性,最后一个DIV填满剩余的部分
<DIV style="border:1px solid red; overflow:hidden;zoom:1;"> <DIV style='floa ...
- 20160506-hibernate入门
HQL和Criteria HQL(Hibernate Query Language) 面向对象的查询语言,与SQL不同,HQL中的对象名是区分大小写的(除了JAVA类和属性其他部分不区分大小写):HQ ...
- C++实现元组
一般我们使用struct时需要在头文件中定义,例如 struct Example { int a; char b; ... }; 这样将数据打包好必须在程序运行之前将其定义好,如果有需求在程序运行时添 ...
- System.Data.SqlClient.SqlError: 对文件……的目录查找失败[转]
System.Data.SqlClient.SqlError: 对文件……的目录查找失败,出现操作系统错误 3 的处理办法 在还原SQL SERVER数据库时出现了查找目录失败的原因,困扰了我一个多小 ...