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 ...
随机推荐
- 【Python】 用python实现定时数据解析服务(前言)
一.Why do it? 背景:项目里上传上来的数据都是未解析的数据,而且数据量还算挺庞大的,每天上传的数据有5kw左右,如果用数据库自带的作业来解析的话,数据库会造成严重的阻塞.因此打算把数据读到外 ...
- Delphi的文件操作
参考自:http://www.cnblogs.com/railgunman/articles/1800318.html Delphi 中默认有input 和 output 两个文件变量,使用可以不用定 ...
- Asyncio中的Task管理
#!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time from random ...
- HDU1294 Rooted Trees Problem(整数划分 组合数学 DP)
讲解见http://www.cnblogs.com/IMGavin/p/5621370.html, 4 可重组合 dfs枚举子树的节点个数,相乘再累加 1 #include<iostream& ...
- Jquery easy UI 上中下三栏布局 分类: ASP.NET 2015-02-06 09:19 368人阅读 评论(0) 收藏
效果图: 源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- C++中单例模式
//C++单例模式:指一个类只生成一个对象 #include <iostream> using namespace std; class A{ public: static A* getA ...
- 汇编学习(一)——win7 64位调出debug
一.安装方法: 1.下载一个dosbox和win7 32位debug.exe,安装dosbox,打开页面 2. 将debug.exe放入磁盘根目录,这里以D盘为例.在dosbox中输入mount c ...
- Hibernate 延迟加载
一.什么是延迟加载? 延迟加载是指当应用程序想要从数据库获取对象时(在没有设置lazy属性值为false),Hibernate只是从数据库获取符合条件的对象的OId从而生成代理对象,并没有加载出对象访 ...
- nginx日志中文变成类似\xE9\xA6\x96\xE9\xA1\xB5-\xE6\x8E\xA8\xE8\x8D\x90的东西,治本方案
这里:https://groups.google.com/forum/#!topic/openresty/NcRSb5gTmVU 主要是: 这与 ngx_lua 无关,是较新的 nginx 核心引入的 ...
- HDU 5875 Function (2016年大连网络赛 H 线段树+gcd)
很简单的一个题的,结果后台数据有误,自己又太傻卡了3个小时... 题意:给你一串数a再给你一些区间(lef,rig),求出a[lef]%a[lef+1]...%a[rig] 题解:我们可以发现数字a对 ...