lightOJ 1068 - Investigation (数位dp)
来源:互联网 发布:50而知天命的英文翻译 编辑:程序博客网 时间:2024/05/19 21:19
1068 - Investigation
PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB
An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is divisible by 3 and 12 (3+7+0+2) is also divisible by 3. This property also holds for the integer 9.
In this problem, we will investigate this property for other integers.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case contains three positive integers A, B and K (1 ≤ A ≤ B < 231 and 0 < K < 10000).
Output
For each case, output the case number and the number of integers in the range [A, B] which are divisible by K and the sum of its digits is also divisible by K.
Sample Input
Output for Sample Input
3
1 20 1
1 20 2
1 1000 4
Case 1: 20
Case 2: 5
Case 3: 64
这种题目考验智商!!
n大于82的时候是没用的,因为数位之和小于82.
还有,k在变化
所以每次都要memset
#include<iostream>using namespace std;#include<cstring>#include<cstdio>#include<algorithm>int digit[20];int k;int dp[10][83][83];int dfs(int pos,int lim,int dig,int sum) { if(pos<0)return dig==0&&sum==0; if(!lim&&(~dp[pos][dig][sum]))return dp[pos][dig][sum]; int ans=0; int len=lim?digit[pos]:9; for(int i=0; i<=len; ++i) { ans+=dfs(pos-1,lim&&(i==len),((dig*10+i)%k)%83,(sum+i)%k); } if(!lim)dp[pos][dig][sum]=ans; return ans;}int work(int val) { int len=0; while(val) { digit[len++]=val%10; val/=10; } return dfs(len-1,1,0,0);}int main() { int n,m,T; int coun=0; scanf("%d",&T); while(T--&&scanf("%d%d%d",&n,&m,&k)) { memset(dp,-1,sizeof(dp)); printf("Case %d: %d\n",++coun,(work(m)-work(n-1))); } return 0;}
- lightoj 1068 Investigation 数位dp
- LightOJ 1068 Investigation (数位dp)
- lightoj 1068 - Investigation (数位DP)
- LightOJ - 1068 Investigation(数位DP)
- LightOJ 1068 - Investigation(数位DP)
- lightoj 1068 - Investigation 数位DP
- lightOJ 1068 - Investigation (数位dp)
- LightOJ 1068 Investigation (数位DP)
- lightoj - 1068 Investigation (数位dp)
- LightOJ 1068 - Investigation (数位dp)
- 【1】【状压DP】LightOJ 1068 Investigation
- Light oj 1068 - Investigation(数位dp)
- Light OJ 1068 Investigation (数位DP)
- Investigation (数位dp)
- lightoj 1068 数位DP
- LightOJ 1068数位dp
- Lightoj 1068 数位dp
- lightoj 1068(数位dp)
- JAVA编程常见错误集锦(1)
- React Native的iOS开发步骤以及崩溃收集
- js入门必读--和你分享js的学习之路1
- 无线循环的两种方式
- android开发类似淘宝京东头条的垂直跑马灯效果
- lightOJ 1068 - Investigation (数位dp)
- ORA-0131:debugging requires the debug connect session system privilege
- 禁用myeclipse updating indexes与大幅优化myeclipse的速度&关闭自动更新
- AbstractList抽象类源码解析
- redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
- android如何编译出适用于不同平台的库文件
- 关于HTML标签的反转义函数
- java 单利模式
- mysql 行转列,套路版