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 ...
随机推荐
- 【android-cocos2d-X2.2 环境配置】在Mac下搭建Cocos2d-X-android开发环境!
仅用于cocos2d-X2.2--cocos2d-X3.4 原文地址:http://blog.csdn.net/dingkun520wy/article/details/17097593 (1)下载 ...
- 域名的a记录转过来他的公网ip
首先 客户要我把域名 和项目进行绑定客户需要提供万网或者新网的账户,登进去域名管理 选项域名管理的A记录定向到那个公网ip上 与服务器做绑定然后 在服务器的iis 上 加个主机头 输入主机头名称 也 ...
- 解决Cisco VPN Client:Reason 442: Failed to Enable Virtual Adapter VPN连接问题
大公司里肯定涉及不同地点的办公问题,这样VPN的使用就频繁了,今天遇到一个VPN连接问题,分享给大家,看一眼,以后不在这问题上耗费太多功夫. 在win7上连接vpn时抛出“failed to enab ...
- IntelliJ IDEA 进行js Debug调试
idea的js调试目前看来不同给力,一是玩转它需要安装谷歌插件支持,二是貌似存在一些bug... 一.新建一个jsp并打上断点 二.调试 idea出现提示: 安装JetBrains IDE Suppo ...
- [转载]C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑
看了很多资料终于搞明白cache中absoluteExpiration,slidingExpiration这两个参数的含义. absoluteExpiration:用于设置绝对过期时间,它表示只要时间 ...
- 【更新链接】U盘启动制作工具(UDTOOL) v3.0.2014.0427
[校验值] 文件: UDTOOLV3_Setup.exe大小: 525 MB版本: 3.0.2014.0427时间: 2014年4月27日MD5: 2E5187B7D9081E8A69B4DC45C8 ...
- Log4J 如何分开Logger输出
今天和两个同事讨论Log4j,他们都需要解决一个问题,怎么分开输出Logger.这么讲不清楚,举个例子: package com.gmail.at.ankyhe.log4jtest; import o ...
- 【C++基础】关键字static 局部变量
1.局部变量 static局部变量和普通局部变量有什么区别:static局部变量只被初始化一次,下一次依据上一次结果值: int test(int j){ static int i=10; i=i+j ...
- 【前端学习】【jQuery选择器】
jQuery选择器 jQuery选择器 本文内容引自于单东林<锋利的jQuery>,未经原作者准许,禁止以商业目的转载发布! 选择器是jQuery的根基,在jQuery中,对事件处 ...
- thinkphp 独立分组配置
详见tp官网. 此处为笔记: <?php return array( // 0,为普通分组,1为独立分组 ', // 独立分组目录 'APP_GROUP_PATH' => 'Modules ...