题目链接

脑子有点乱,有的地方写错了,尚大婶鄙视了。。。

来个模版的。

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL __int64
LL dp[][];
int num[];
LL dfs(int pos,int pre,int bound)
{
int end,tpre,i;
LL ans = ;
if(pos == -)
return pre == ;
if(!bound&&dp[pos][pre] != -)
return dp[pos][pre];
end = bound ? num[pos] : ;
for(i = ;i <= end;i ++)
{
tpre = (pre + i)%;
ans += dfs(pos-,tpre,bound&&i == end);
}
if(!bound)
dp[pos][pre] = ans;
return ans;
}
LL judge(LL x)
{
int pos = ;
if(x < )
return ;
while(x)
{
num[pos++] = x%;
x = x/;
}
return dfs(pos-,,);
}
int main()
{
int t,cas = ;
LL x,y;
memset(dp,-,sizeof(dp));
scanf("%d",&t);
while(t--)
{
scanf("%I64d%I64d",&x,&y);
printf("Case #%d: ",cas++);
printf("%I64d\n",judge(y)-judge(x-));
}
return ;
}
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <ctime>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL __int64
LL dp[][];
LL judge(LL x)
{
int num[],n = ,sum,i,j;
LL ans = ;
if(x < )
return ;
else if(x == )
return ;
while(x)
{
num[n ++] = x%;
x /= ;
}
if(n == )
return ;
ans = dp[n-][];
for(i = ;i < num[n-];i ++)
{
ans += dp[n-][-i];
}
sum = num[n-];
for(i = n-;i >= ;i --)
{
if(i == )
{
for(j = ;j <= num[i];j ++)
if((sum + j)% == )
ans ++;
break;
}
for(j = ;j < num[i];j ++)
ans += dp[i][(-sum-j)%];
sum = (sum + num[i])%;
}
return ans;
}
int main()
{
int i,j,k,t,cas = ;
LL x,y;
for(i = ;i < ;i ++)
dp[][i] = ;
for(i = ;i <= ;i ++)
{
for(j = ;j < ;j ++)
{
for(k = ;k < ;k ++)
{
dp[i][(j+k)%] += dp[i-][j];
}
}
}
scanf("%d",&t);
while(t--)
{
scanf("%I64d%I64d",&x,&y);
printf("Case #%d: %I64d\n",cas ++,judge(y)-judge(x-));
}
return ;
}

HDU 4722 Good Numbers(DP)的更多相关文章

  1. 【数位DP】 HDU 4722 Good Numbers

    原题直通车: HDU  4722  Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...

  2. HDOJ(HDU).1058 Humble Numbers (DP)

    HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...

  3. HDU 4722 Good Numbers

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 Good Numbers Time Limit: 2000/1000 MS (Java/Othe ...

  4. HDU 4722 Good Numbers(位数DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description If we sum up every digit of a number and the result can be exactly divided by 10, we say ...

  5. hdu 4722 Good Numbers( 数位dp入门)

    Good Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. HDU - 4722 Good Numbers 【找规律 or 数位dp模板】

    If we sum up every digit of a number and the result can be exactly divided by 10, we say this number ...

  7. hdu 4722 Good Numbers 数位DP

    数位DP!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include< ...

  8. HDU 4722:Good Numbers(数位DP)

    类型:数位DP 题意:定义一个Good Number 为 一个数所有位数相加的和%10==0.问[A,B]之间有多少Good Number. 方法: 正常“暴力”的定义状态:(i,d,相关量) 定义d ...

  9. hdu 4722 Good Numbers 规律 数位dp

    #include<iostream> #include<cstring> #include<cstdio> #include<vector> #incl ...

随机推荐

  1. Eclipse 快捷键 转换为Netbeans 快捷键

    一直使用netbeans IDE开发,习惯了netbeans的快捷键,最近要开发个app就选择了H5. 接着使用了HBuilder (基于Eclipse开发) 总体来讲这个IDE还可以,不管是代码提示 ...

  2. 【sicily】卡片游戏

    卡片游戏  Time Limit: 1sec    Memory Limit:32MB Description 桌上有一叠牌,从第一张牌(即位于顶面的牌)开始从上往下依次编号为1~n.当至少还剩两张牌 ...

  3. Linq To Sql中实现Left Join与Inner Join使用Linq语法与lambda表达式

    当前有两个表,sgroup与sgroupuser,两者通过gKey关联,而sgroup表记录的是组,而sgroupuser记录是组中的用户,因此在sgroupuser中不一定有数据.需要使用Left ...

  4. 攻城狮在路上(叁)Linux(二十三)--- linux磁盘参数修改(设备代码、设备名)

    一.mknod:设置设备代码 linux中,所有的设备都是用文件来表示,文件通过major与minor数值来判断. major为主设备代码,minor为设备代码(需要查询),示例如下: /dev/hd ...

  5. 2-04使用SQL语句创建数据库

    下面是创建数据库的一些语法: USE master--指向当前使用的数据库 GO--批处理的标志 CREATE DATABASE E_Market--创建E_market数据库 ON PRMARY-- ...

  6. wp8 入门到精通 Gallery

    <Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.Resources> ...

  7. [JavaCore] 微信手机浏览器版本判断

    公司要做微支付,微信浏览器版本要大于5 package com.garinzhang.web.weixin; import org.apache.commons.lang.StringUtils; i ...

  8. PMP - 项目管理思维导图

  9. 硬盘格式是MBR、GPT

    装win7 64位要求硬盘格式是MBR 现在预装 Win8 的电脑大多是采用新版 UEFI 固件 + GPT 格式磁盘 GPT模式是针对整个硬盘的初始化而言,因此不存在某一个分区是GPT模式的说法.转 ...

  10. input实时监控和获取焦点的问题,oninput,ononfocus

    1.input监控实时输入问题,google浏览器使用oninput,其他浏览器(IE6/7/8)使用onpropertychange var ie = !!window.ActiveXObject; ...