题意:有标号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 ;
}

最新文章

  1. 分布式服务协调员zookeeper - 应用场景和监控
  2. .Net中Remoting通信机制
  3. 简单的后台json,前台解析 操作
  4. 【腾讯Bugly干货分享】微信终端跨平台组件 mars 系列(一) - 高性能日志模块xlog
  5. JavaScript之旅(三)
  6. HTTP Error 403没有了,但是中文全都是乱码。又是怎么回事?
  7. PHP 判断是否包含某字符串
  8. nginx比较apache
  9. NGUI系列教程一
  10. SQL Server 的远程连接(转载)
  11. C# 文件读写异常“正由另一进程使用,因此该进程无法访问该文件”
  12. github三大步骤
  13. Apache Commons Pool2 源码分析 | Apache Commons Pool2 Source Code Analysis
  14. CentOS 7下安装X Window
  15. 一个突发性的误解C# 引用类型
  16. 建立、配置和使用Activity——启动其他Activity并返回结果
  17. 线性表的链式存储结构的实现及其应用(C/C++实现)
  18. 《java入门第一季》之面向对象(包概述)
  19. Microsoft Dynamics CRM 9.0 OP 版本 安装 的那些 雷
  20. JAVA经典算法50题(转)

热门文章

  1. sql shard/partition
  2. validate[.unobtrusive]和Bootstrap实现tooltip错误提示
  3. Hadoop的安装与配置说明
  4. js检测浏览器版本代码,兼容ie11
  5. Visual C++ unicode and utf8 转换
  6. tomcat集群部署
  7. mybatis的知识点总结
  8. SPRING IN ACTION 第4版笔记-第九章Securing web applications-009-拦截请求()
  9. java去除重复的字符串和移除不想要的字符串
  10. JavaScript DOM高级程序设计 4.3控制事件流和注册事件侦听器--我要坚持到底!