SGU_390_Tickets(另类数位DP)
Tickets
Time Limit : 1000/500ms (Java/Other) Memory Limit : 524288/262144K (Java/Other)
Total Submission(s) : 79 Accepted Submission(s) : 16
Conductor is quite a boring profession, as all you have to do is just to sell tickets to the passengers. So no wonder that once upon a time in a faraway galaxy one conductor decided to diversify this occupation. Now this conductor sells several tickets at a
time to each passenger. More precisely, he successively gives tickets to the passenger until the sum of the digits on all the tickets given becomes not less than some integer number k. Then this process repeats for the next passenger. Initially conductor
has a tape of tickets numbered successively from l to r, inclusive. This way of tickets distribution is quite good, because passengers are glad to get several tickets when they pay only for one. But there is one disadvantage. Since each passenger
gets several tickets, it is possible that conductor won't be able to serve all passengers. Your task is to help conductor in this difficult situation. You should calculate how many passengers is the conductor able to serve.
Input file contains three integer numbers l, r and k (1 ≤ l ≤ r ≤ 1018, 1 ≤ k ≤ 1000).
Output should contain exactly one number — the answer to the problem.
sample input |
sample output |
40 218 57 |
29 |
题意:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define F(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long LL;
typedef pair<LL,LL>P;
int l[],r[],ln,rn,vis[][][];
LL a,b,m;
P dp[][][];
P dfs(int pos=rn,int sum=,int rem=,bool up=,bool dn=){
if(!pos)if(sum+rem>=m)return P(,);else return P(,sum+rem);
if(vis[pos][sum][rem]&&!up&&!dn)return dp[pos][sum][rem];
int st=dn?l[pos]:,end=up?r[pos]:;P ans=P(,rem);
F(i,st,end){
P tp=dfs(pos-,sum+i,ans.second,up&&i==end,dn&&i==st);
ans.first+=tp.first,ans.second=tp.second;
}
if(!up&&!dn)dp[pos][sum][rem]=ans,vis[pos][sum][rem]=;
return ans;
} int main(){
while(~scanf("%I64d%I64d%I64d",&a,&b,&m)){
memset(vis,,sizeof(vis));
for(rn=;b;b/=)r[++rn]=b%;
for(ln=;ln<rn;a/=)l[++ln]=a%;
printf("%I64d\n",dfs().first);
}
return ;
}
SGU_390_Tickets(另类数位DP)的更多相关文章
- 【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 ...
- 数位DP GYM 100827 E Hill Number
题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++. ...
- 数位dp总结
由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...
- 数位DP入门
HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...
- 数位DP之奥义
恩是的没错数位DP的奥义就是一个简练的dfs模板 int dfs(int position, int condition, bool boundary) { ) return (condition ? ...
- 浅谈数位DP
在了解数位dp之前,先来看一个问题: 例1.求a~b中不包含49的数的个数. 0 < a.b < 2*10^9 注意到n的数据范围非常大,暴力求解是不可能的,考虑dp,如果直接记录下数字, ...
随机推荐
- 依赖跟踪如何工作的(How dependency tracking works)
这一块主要是理论的讲解,本人刚接触这块不久,就不敢翻译了,请参见园子里其他人的现有文章 http://www.cnblogs.com/TomXu/archive/2011/11/22/2256820. ...
- 设计模式5 合成模式 COMPOSITE
一个合成是一组对象,其中某些对象可能包含其他对象. 目的:可以让客户程序把单个基本对象和对象的合成用一种统一的方式处理. 5.1 普通合成 Technorati Tags: adsf
- VS2013程序打包部署详细图解
目录(?)[+] 新建项目 FILE –> New –> Project,如下图所示: 注意:如果 InstallShield Limited Edition Project 显 ...
- easyui-datagrid加载时的效率低下,解决方案
在360浏览器中 使用easyui datagrid 加载数据是效率低下,有时候会出现卡机. 可以修改easyui源码进行解决.
- oracle行转列函数
- FZU 1502 Letter Deletion
最长公共子序列. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...
- WebService测试方案
1.WebService简介 WebService是一种革命性的分布式计算技术,本质上就是网络上可用的API,可以直接在网络环境调用的方法. WebService常用的框架有axis.xfire.cx ...
- Android软件盘InputMethodManager
调用下面代码:(第一次调用显示,再次调用则隐藏,如此反复),this指activity InputMethodManager imm = (InputMethodManager)this.getSys ...
- hdu_5748_Bellovin(LIS)
题目链接:hdu_5748_Bellovin 题意: 给你一个数列ai,设f(a1,a2,a3,..an)=(f1,f2,f3,...,fn),其中fi表示以ai结尾的最长递增子序列长度,注意:必须要 ...
- 第3章 Java语言基础----成员变量与局部变量
在对局部变量进行赋值时,不能对非静态字段age进行静态引用,图1错误,加上static后图二正确,图3与图4类似,如下图所示: 图1图2 图3图4 2.成员变量times在类中定义,局部变量times ...