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 ...
随机推荐
- 重温WCF之数据契约中使用枚举(转载)(十一)
转载地址:http://www.zhuli8.com/wcf/EnumMember.html 枚举类型的定义总是支持序列化的.当我们定义一个新的枚举时,不必应用DataContract特性,就可以在数 ...
- 【翻译十三】java-并发之饥饿与活锁
Starvation and Livelock Starvation and livelock are much less common a problem than deadlock, but ar ...
- Asyncio中的Task管理
#!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time from random ...
- Java Hour 63 反射
首先要感谢下这位可爱的作者: http://www.cnblogs.com/rollenholt/archive/2011/09/02/2163758.html. 本文是基于其模板的模仿实验. 获得C ...
- hdu 2891 中国剩余定理
从6点看到10点,硬是没算出来,早知道玩游戏去了,艹,明天继续看 不爽,起来再看,终于算是弄懂了,以后超过一个小时的题不会再看了,不是题目看不懂,是水平不够 #include<cstdio> ...
- C# 获取wave文件信息【转】
public class WaveHelper { /// <summary> /// 数据流 /// </summary> private Stream m_WaveData ...
- Input对象的type类型
Input表示Form表单中的一种输入对象,其又随Type类型的不同而分文本输入框,密码输入框,单选/复选框,提交/重置按钮等,下面一一介绍. 1,type=text 输入类型是text ...
- SQL简繁转换函数
declare @jall nvarchar(4000),@fall nvarchar(4000) select @jall=N'啊阿埃挨哎唉哀皑癌蔼矮艾碍爱隘鞍氨安俺按暗岸胺案肮昂盎凹敖熬翱袄傲奥懊 ...
- Jmeter分布式测试搭建(二)
Jmeter运行的时候十分耗内存和cpu,跑到500多个进程的时候,就卡死了.我们测试时,如果进行大数据量的并发测试时,单个电脑的CPU和内存可能无法承受,这个时候,我们需要进行一个分布式的测试,比如 ...
- DLL中传递STL参数(如Vector或者list等)会遇到的问题[转载]
最近的一个项目中遇到了调用别人的sdk接口(dll库)而传给我的是一个vector指针,用完之后还要我来删除的情况.这个过程中首先就是在我的exe中将其vector指针转为相应指针再获取vector中 ...