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 ...
随机推荐
- sdut 2125串结构练习--字符串匹配【两种KMP算法】
串结构练习——字符串匹配 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目链接:http://acm.sdut.edu.cn/sduto ...
- 随机生成字符串-php-js
js <script language="javascript"> function randomString(len) { len = len || 32; var ...
- [CentOS]安装软件:/lib/ld-linux.so.2: bad ELF interpreter解决
转自:http://blog.csdn.net/wanglei2258/article/details/24961233 [CentOS]安装软件:/lib/ld-linux.so.2: bad EL ...
- 链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的
解决方法: 1.打开该项目的"属性页"对话框. 2.单击"链接器"文件夹. 3.单击"命令行"属性页. 4.将 /SAFESEH:NO 键入 ...
- Zigzag convert
public static String Convert(String s,int row) { char[] c=s.toCharArray(); int len=s.length(); Strin ...
- 字符串截取函数--C语言(转)
#include<stdio.h> #include<stdlib.h> char* substring(char* ch,int pos,int length) { char ...
- Spark Streaming容错的改进和零数据丢失
本文来自Spark Streaming项目带头人 Tathagata Das的博客文章,他现在就职于Databricks公司.过去曾在UC Berkeley的AMPLab实验室进行大数据和Spark ...
- sublime快捷键大全
转自:http://blog.useasp.net/archive/2013/06/14/sublime-text-2-all-default-Shortcuts-table-on-windows-t ...
- UVA 11987 Almost Union-Find (并查集+删边)
开始给你n个集合,m种操作,初始集合:{1}, {2}, {3}, … , {n} 操作有三种: 1 xx1 yy1 : 合并xx1与yy1两个集合 2 xx1 yy1 :将xx1元素分离出来合到yy ...
- 利用scp传输文件小结
从本地复制到远程 scp mysql-5.5.29-linux2.6-x86_64.tar.gz 192.168.1.11:/opt 指定端口: scp -P 60022 /opt/ray/nginx ...