简单数位DP
https://cn.vjudge.net/problem/HDU-4722
懒得写看,代码注释吧;主要存板子
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long LL;
const int INF=2e9+1e8; const int MOD=1e9+;
const int MAXSIZE=1e6+;
const double eps=0.0000000001;
void fre()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
}
#define memst(a,b) memset(a,b,sizeof(a))
#define fr(i,a,n) for(int i=a;i<n;i++) /**
dp[i][j] 代表从高位到i位求和余数为j的;先写dfs,最后再把dp加入就好了,
还有爆int 需要注意。 */ LL dp[][];
int bits[];
LL dfs(int pos,int sum,bool flag)//pos代表位置,sum代表求和之后的余数,flag代表是否是0~9
{
if(pos==) return sum==;
if(flag&&dp[pos][sum]!=-) return dp[pos][sum];
int len=flag?:bits[pos];//flag为真 0~9,
LL res=;
for(int i=;i<=len;i++)
res+=dfs(pos-,(sum+i)%,i!=len||flag);//
if(flag) dp[pos][sum]=res;
return res;
} LL get(LL x)
{
if(x<) return ;
int i=;
while(x>) bits[++i]=x%,x/=;
return dfs(i,,false);
}
int main()
{
// test();
int cas=,ncase;
scanf("%d",&ncase);
memset(dp,-,sizeof(dp));
while(ncase--)
{
int i=;
LL l,r;
cin>>l>>r;
printf("Case #%d: %I64d\n",++cas,get(r)-get(l-));
}
return ;
} /**************************************************/
/** Copyright Notice **/
/** writer: wurong **/
/** school: nyist **/
/** blog : http://blog.csdn.net/wr_technology **/
/**************************************************/
简单数位DP的更多相关文章
- HDU 2089 简单数位dp
1.HDU 2089 不要62 简单数位dp 2.总结:看了题解才敲出来的,还是好弱.. #include<iostream> #include<cstring> #i ...
- windy数(简单数位DP)
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 6306 Solved: 2810[Submit][Sta ...
- hdu4722之简单数位dp
Good Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- [DP]数位DP总结
数位DP总结 By Wine93 2013.7 1.学习链接 [数位DP] Step by Step http://blog.csdn.net/dslovemz/article/details/ ...
- POJ 3252 Round Number(数位DP)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6983 Accepted: 2384 Des ...
- 数位dp 的简单入门
时间紧张,就不讲那么详细了. 之前一直被深搜代码误解,以为数位dp 其实就是记忆化深搜...(虽说爆搜确实很舒服而且还好想) 但是后来发现数位dp 的标准格式其实是 预处理 + dp ...... 数 ...
- 数位dp 简单入门
推荐博客 推荐博客 数位dp是一种计数用的dp,一般就是要统计一个区间[le,ri]内满足一些条件数的个数.所谓数位dp,字面意思就是在数位上进行dp咯.数位还算是比较好听的名字,数位的含义:一个数有 ...
- cojs 简单的数位DP 题解报告
首先这道题真的是个数位DP 我们考虑所有的限制: 首先第六个限制和第二个限制是重复的,保留第二个限制即可 第五个限制在转移中可以判断,不用放在状态里 对于第一个限制,我们可以增加一维表示余数即可 对于 ...
- [Swust OJ 648]--简单字典(数位dp)
题目链接:http://acm.swust.edu.cn/problem/0648/ Time limit(ms): 1000 Memory limit(kb): 65535 有这样一本字典,它每 ...
随机推荐
- javascript对象初探 (五)--- 函数对象的属性
与其他对象相同的是,函数对象中也有一个叫做constructor的属性,其引用就是Function()这个构造函数. function her(a){ return a; } console.log( ...
- JavaScript的Object的一些静态方法(*************************************************************)
0. 开场白 这是每天学点javascript系列文章的第一篇,我觉得把这些相关的笔记整理成系列文章会很不错,方便读者阅读的同时也方便自己回顾.最近javascript已经成为了我生活的一部分了,虽然 ...
- GCD CoreData 简化CoreData操作(转)
来自会员带睡帽的青蛙的分享: 短话长说,开始写这个小工具到现在有两个月了,虽然东西少,但是很精练,改了又改,期间有不少问题 在坛子里获得了不少帮助 谢谢各位大大. 就是两个文件一个类 CoreData ...
- Golang协程与通道整理
协程goroutine 不由OS调度,而是用户层自行释放CPU,从而在执行体之间切换.Go在底层进行协助实现 涉及系统调用的地方由Go标准库协助释放CPU 总之,不通 ...
- 利用Thinkphp 5缓存漏洞实现前台Getshell
0×00 背景 网站为了实现加速访问,会将用户访问过的页面存入缓存来减小数据库查询的开销.而Thinkphp5框架的缓存漏洞使得在缓存中注入代码成为可能.(漏洞详情见参考资料) 本文将会详细讲解: 1 ...
- 转:android studio入门合集
http://blog.csdn.net/column/details/zsl-androidstudio.html
- HDU-3681-Prison Break(BFS+状压DP+二分)
Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one da ...
- viewpager 跳转到指定页面
viewPager.setCurrentItem(getUserIndex(userId)); seCurrentItem是定位到指定页面参数是position
- C语言--函数篇
1-1.函数简单调用 1 #include<stdio.h> 2 #include<string.h> 3 #include<windows.h> 4 int ...
- CUGBACM_Summer_Tranning1 二进制枚举+模拟+离散化
整体感觉:这个组队赛收获还挺多的.自从期末考试以后已经有一个多月没有 做过组队赛了吧,可是这暑假第一次组队赛就找回了曾经的感觉.还挺不错的!继续努力!! 改进的地方:这次组队赛開始的时候题目比較难读懂 ...