HDU 4722 Good Numbers(DP)
脑子有点乱,有的地方写错了,尚大婶鄙视了。。。
来个模版的。
#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)的更多相关文章
- 【数位DP】 HDU 4722 Good Numbers
原题直通车: HDU 4722 Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...
- HDOJ(HDU).1058 Humble Numbers (DP)
HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...
- HDU 4722 Good Numbers
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 Good Numbers Time Limit: 2000/1000 MS (Java/Othe ...
- 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 ...
- hdu 4722 Good Numbers( 数位dp入门)
Good Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 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 ...
- hdu 4722 Good Numbers 数位DP
数位DP!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include< ...
- HDU 4722:Good Numbers(数位DP)
类型:数位DP 题意:定义一个Good Number 为 一个数所有位数相加的和%10==0.问[A,B]之间有多少Good Number. 方法: 正常“暴力”的定义状态:(i,d,相关量) 定义d ...
- hdu 4722 Good Numbers 规律 数位dp
#include<iostream> #include<cstring> #include<cstdio> #include<vector> #incl ...
随机推荐
- 自己制作QQ空间音乐的具体方法
1.打开QQ邮箱找到左栏下方的“文件中转站”--点击收藏文件--上传到收藏 将MP3或WMA音乐文件上传 上传完成点下载 下图: 2.点“保存”将最上面一排的地址全部复制 下图 3.为了更 ...
- 禁用编译器自动生成的函数(Effective C++之06)
如果想让你的类定义出来的对象是独一无二的,即对象无法被复制,或者使用赋值操作符赋给另外一个对象,那么最好的方法就是禁用拷贝构造函数和赋值操作符.下面介绍几种禁用的方法.(方法来自Effective C ...
- [荐]使用jQuery清空file文件域
file是文本域,我们一般都会使用它来上传文件,在上传文件时我们需要验证,验证完成后,如果存在错误,为了防止将错误信息也上传上去,我们总是希望能够将其清空.但是在IE中,为了安全起见它是不允许我们改变 ...
- python客户端编程
上一篇说了最为底层的用来网络通讯的套接字.有很多基于套接字的一些协议,这些协议构成了当今互联网大多数客户服务器应用的核心 其实这些协议时在套接字上面的进一层封装用来完成特定的应用,这些应用主要包括: ...
- 及其简短的Splay代码
#include <stdio.h> #include <queue> #include <algorithm> #include <stdlib.h> ...
- Eclipse首字母快捷设置
windows->Preference ,然后:
- MVC3实现多个按钮提交
有时我们需要在同一个Form表单中进行多个按钮的提交,来完成不同的功能.因为MVC中一个表单默认只能提交到一个Action处理,相对比较麻烦. 1.使用客户端脚本 我们可以view中加上如下代码: & ...
- JavaScrip入门(3)
函数: var m2=function(){ console.log('2222'); } console.log(typeof(m2)); 输出结果:test.html:31 function js ...
- jQuery-认识JQuery,jQuery选择器
认识JQuery: 1.window.onload与$(document).ready()的区别 window.onload $(document).ready() 执行时机 必须等待网页中的所有内容 ...
- http://blog.sina.com.cn/s/blog_5bd6b4510101585x.html
http://blog.sina.com.cn/s/blog_5bd6b4510101585x.html