题目传送门

 /*
找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one ()
http://www.cnblogs.com/crazyapple/p/3315436.html
数位DP:http://blog.csdn.net/libin56842/article/details/11580497
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f; int is_one(long long n)
{
long long m = n;
long long i = n / * ; for (; i<=m; ++i)
{
long long tmp = i; int sum = ;
while (tmp)
{
sum += tmp % ;
tmp /= ;
}
if (sum % == ) return ;
} return ;
} long long get_num(long long n)
{
if (n < ) return ;
if (n <= ) return ; return n/ + is_one (n);
} int main(void) //HDOJ 4722 Good Numbers
{
//freopen ("G.in", "r", stdin); int t, cas = ;
long long l, r;
scanf ("%d", &t);
while (t--)
{
scanf ("%I64d%I64d", &l, &r); printf ("Case #%d: %I64d\n", ++cas, get_num (r) - get_num (l-));
} return ;
} /*
Case #1: 0
Case #2: 1
Case #3: 1
*/

 /*
数位DP:基础题,对于一个数,把它每位数分出来,从最高位开始枚举。dp[i][(j+k)%10] += dp[i+1][j];
dp[i][j]表示前i位数和取模是j的个数
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; typedef long long ll;
const int MAXN = ;
const int INF = 0x3f3f3f3f;
ll dp[MAXN][MAXN];
int dig[MAXN]; ll work(ll n) {
ll tmp = n; int len = ;
memset (dig, , sizeof (dig));
while (tmp) {
dig[++len] = tmp % ;
tmp /= ;
}
memset (dp, , sizeof (dp)); int x = ;
for (int i=len; i>=; --i) {
for (int j=; j<; ++j) {
for (int k=; k<; ++k) {
dp[i][(j+k)%] += dp[i+][j];
}
}
for (int j=; j<dig[i]; ++j) dp[i][(x+j)%]++;
x = (x + dig[i]) % ;
}
if (!x) dp[][]++;
return dp[][];
} int main(void) { //HDOJ 4722 Good Numbers
int T, cas = ; scanf ("%d", &T);
while (T--) {
ll l, r; scanf ("%I64d%I64d", &l, &r);
printf ("Case #%d: %I64d\n", ++cas, work (r) - work (l-));
} return ;
}

数位DP

最新文章

  1. 关于linux下DB2创建数据库报错问题
  2. jqueryUI小案例
  3. Xcode里-ObjC, -all_load, -force_load
  4. IOS - Foundation和Core Foundation掺杂使用桥接
  5. ural 1145. Rope in the Labyrinth
  6. ios-滚动视图滚动取消键盘
  7. Thinkphp单字母快捷键
  8. 【译】Python Lex Yacc手册
  9. [OpenCV] HighGUI
  10. 监控Mysql主从环境下Slave延迟状态的操作记录
  11. 配置错误 在唯一密钥属性“fileExtension”设置为“.log”时,无法添加类型为“mimeMap”的重复集合项
  12. 【解决】该任务映像已损坏或已篡改。(异常来自HRESULT:0x80041321)
  13. 百度的一个Ajax跨域方法 JavaScript是没有域的限制
  14. 【单点更新,区间查询,线段树】【HDU1166】【敌兵布阵】
  15. poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)
  16. Selenium在定位的class含有空格的复合类的解决办法整理
  17. (办公)mysql连接不上(java.sql.SQLException: null, message from server: &quot;Host &#39;LAPTOP-O0GA2P8J&#39; is not allowed to connect to this MySQL server&quot;)(转)
  18. bootstrap-treeview分级展示列表树的实现
  19. Ubuntu16.04下安装Hyperledger Fabric 1.0.0
  20. 爬楼梯的golang实现

热门文章

  1. FrameSize、WinSize、VisibleSize、VisibleOrigin区别
  2. spring - 自定义注解
  3. Mysql limit offset
  4. [Effective JavaScript 笔记]第55条:接收关键字参数的选项对象
  5. python学习之最简单的获取本机ip信息的小程序
  6. [codeforces 241]A. Old Peykan
  7. HDU1711
  8. HDU 3371 kruscal/prim求最小生成树 Connect the Cities 大坑大坑
  9. 安装mac os x时about a second remaining解决方法
  10. 【Web】关于URL中文乱码问题