SGU 390-Tickets(数位dp)
题意:有标号l-r的票,要给路人发,当给的票的编号的各数位的总和(可能一个人多张票)不小k时,才开始发给下一个人,求能发多少人。
分析:这个题挺难想的,参考了一下题解,dp[i][sum][left] 长度i 当前数位和sum 前一子树剩余的和
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
ll l,r;
int k,lbit[],rbit[],used[][][];
struct node{
ll num,left;//num能发的人数、left前一子树剩余和
node(ll num = , ll left = ) : num(num), left(left) {}
node operator += (node b)
{
num += b.num;
left = b.left;
return *this;
}
}dp[][][];
node dfs(int i,int sum,int left,int le,int re){
if(i==){
if(sum+left>=k)
return node(,);
return node(,sum+left);
}
if(used[i][sum][left]&&!le&&!re)
return dp[i][sum][left];
int ll=le?lbit[i]:;
int rr=re?rbit[i]:;
node a(,left);
for(int v=ll;v<=rr;++v){
a+=dfs(i-,sum+v,a.left,le&&(v==ll),re&&(v==rr));
}
if(!le&&!re){
dp[i][sum][left]=a;
used[i][sum][left]=;
}
return a;
}
void solve(){
memset(used,,sizeof(used));
memset(dp,,sizeof(dp));
int len=;
while(r){
rbit[++len]=r%;
r/=;
lbit[len]=l%;
l/=;
}
node t=dfs(len,,,,);
printf("%I64d\n",t.num);
}
int main()
{
scanf("%I64d%I64d%d",&l,&r,&k);
solve();
return ;
}
SGU 390-Tickets(数位dp)的更多相关文章
- Codeforces Gym 100418J Lucky tickets 数位DP
Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- [DP]数位DP总结
数位DP总结 By Wine93 2013.7 1.学习链接 [数位DP] Step by Step http://blog.csdn.net/dslovemz/article/details/ ...
- 【SGU 390】Tickets (数位DP)
Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell ...
- Gym 100418J Lucky tickets(数位dp)
题意:给定一个n.求区间[1, n]之间的全部的a的个数.a满足: a能整除 把a表示自身二进制以后1的个数 思路:题意非常绕.... 数位dp,对于全部可能的1的个数我们都dfs一次 对于某一个可 ...
- SGU_390_Tickets(另类数位DP)
Tickets Time Limit : 1000/500ms (Java/Other) Memory Limit : 524288/262144K (Java/Other) Total Subm ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- bzoj1026数位dp
基础的数位dp 但是ce了一发,(abs难道不是cmath里的吗?改成bits/stdc++.h就过了) #include <bits/stdc++.h> using namespace ...
- uva12063数位dp
辣鸡军训毁我青春!!! 因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题 于是在猫大的帮助下我发现这道习题是数位dp 然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试 果然 ...
- HDU2089 不要62[数位DP]
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- eclipse html插件的下载和安装
需求:需要在eclipse里面编辑html和jsp,语法高亮和语法提示,自动补全等. 1.下载GEF(依赖包): http://www.eclipse.org/downloads/download.p ...
- 解决Cisco VPN Client:Reason 442: Failed to Enable Virtual Adapter VPN连接问题
大公司里肯定涉及不同地点的办公问题,这样VPN的使用就频繁了,今天遇到一个VPN连接问题,分享给大家,看一眼,以后不在这问题上耗费太多功夫. 在win7上连接vpn时抛出“failed to enab ...
- nginx配置location [=|~|~*|^~] /uri/ { … }用法
版权声明:https://github.com/wusuopubupt ====== nginx location语法 基本语法:location [=|~|~*|^~] /uri/ { … } = ...
- 动态内存 this指针
#include <iostream> #include <string> class Company { public: Company(std::string theNam ...
- Objective C 四舍五入,float处理
NSLog(@"平方:%.f", pow(3,2) ); //result 9 NSLog(@"上舍入:%.f", ceil(3.000000000001)); ...
- [DP] 堆盒子问题
给一堆盒子,知道每个盒子的三围(长宽高),盒子正面朝你,不能旋转摆放,按照大的放在小的下面的原则堆起来,必须是 strictly larger,同样大小的盒子不行,问怎么样堆到最大的高度? 思路:动态 ...
- redhat_suse双系统引导
先装suse11系统,再装redhat6后出现引导中suse系统无法启动解决方法:在redhat中将suse所在分区挂载出来,找其boot/grub/menu.lst下的启动项,将该启动项复制到red ...
- IOS xib生成界面和代码生成界面两种方式混合
应用程序代理类 WKAppDelegate.m // // WKAppDelegate.m // HelloWorld // // Created by easy5 on 13-9-18. // Co ...
- Discuz使用tools修复数据文件后,访问URL多出/source/plugin/tools,导致文章栏目无法访问
今天我的婚嫁亲子网数据库出了点错误,于是就用dz官方的tool工具修复了以下,然后就发生了这个错误.. 本来频道页面的地址是:http://www.ifen8.com/article/ 结果自动跳转成 ...
- 几款国产开源的Windows界面库
上次介绍的几款图形界面库http://blog.okbase.net/vchelp/archive/23.html都是国外的开源项目,今天介绍的几款都是国人的开源项目,大部分是采用DirectUI设计 ...