HDU 4722 (数位DP 水~)
来源:互联网 发布:软件测试 培训课程 编辑:程序博客网 时间:2024/06/05 14:45
Good Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3814 Accepted Submission(s): 1213
Problem Description
If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number.
You are required to count the number of good numbers in the range from A to B, inclusive.
You are required to count the number of good numbers in the range from A to B, inclusive.
Input
The first line has a number T (T <= 10000) , indicating the number of test cases.
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).
Output
For test case X, output "Case #X: " first, then output the number of good numbers in a single line.
Sample Input
21 101 20
Sample Output
Case #1: 0Case #2: 1HintThe answer maybe very large, we recommend you to use long long instead of int.
求出区间里面每个数位和模10余0的个数.
#include <bits/stdc++.h>using namespace std;#define mod 1000000007#define maxn 22typedef long long ull;ull a, b;int bit[maxn], l;ull dp[maxn][11];ull dfs (int pos, int m1, bool f2) { //当前的位数 之前模10余数 是不是可以取到9 if (pos == 0) { return m1 == 0; } if (f2 && dp[pos][m1] != -1) { return dp[pos][m1]; } ull Max = (f2 ? 9 : bit[pos]); ull ans = 0; for (int i = 0; i <= Max; i++) { ans += dfs (pos-1, (m1+i)%10, f2 || (i<Max)); } if (f2) dp[pos][m1] = ans; return ans;}ull f (ull num) { l = 0; while (num) { bit[++l] = num%10; num /= 10; } return dfs (l, 0, 0);}int main () { //freopen ("in.txt", "r", stdin); int t, kase = 0; memset (dp, -1, sizeof dp); cin >> t; while (t--) { cin >> a >> b; printf ("Case #%d: %lld\n", ++kase, f (b)-f (a-1)); } return 0;}
0 0
- HDU 4722 (数位DP 水~)
- hdu 4722 数位DP
- hdu 4722 数位dp
- HDU 4722 数位DP
- HDU 3555 水数位dp
- HDU 4278 水~ 数位DP
- HDU 3652 (数位DP 水~)
- hdu 4722 Good Numbers 数位dp
- hdu 4722 good number 数位dp入门
- 【数位DP】 HDU 4722 Good Numbers
- hdu 4722 Good Numbers 数位dp
- hdu 4722 数位dp 简单题
- HDU 4722 Good Numbers (数位dp)
- [数位dp] hdu 4722 Good Numbers
- hdu 4722 Good Numbers(数位dp)
- hdu 4722 Good numbers(数位DP)
- HDU 4722-Good Numbers-数位dp
- 【HDU 4722】Good Numbers(数位dp)
- 2016第七届蓝桥杯-方格填数
- LeetCode-136. Single Number/137. Single Number II/260. Single Number III
- 我的第一篇csdn博客
- Ubuntu终端(Terminal)常用快捷键
- Android 四大组件之ContentProvider工作原理
- HDU 4722 (数位DP 水~)
- 基于echo例子的netty4通信总结
- 单词拼接
- linux 定时任务 crontab
- 学习笔记:Android里JSON解析的几种方法
- 瑞昱RTL8710对标乐鑫ESP8266 谁将成为物联网首选
- 随笔之ros多线程
- 欢迎使用CSDN-markdown编辑器
- android studio 导入 xutils3.0 到项目中