博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Timus Online Judge 1057. Amount of Degrees(数位dp)
阅读量:7013 次
发布时间:2019-06-28

本文共 1803 字,大约阅读时间需要 6 分钟。

1057. Amount of Degrees

Time limit: 1.0 second
Memory limit: 64 MB
Create a code to determine the amount of integers, lying in the set [
X;
Y] and being a sum of exactly
K different integer degrees of 
B.
Example. Let 
X=15, 
Y=20, 
K=2, 
B=2. By this example 3 numbers are the sum of exactly two integer degrees of number 2:
17 = 2
4+2
0,
18 = 2
4+2
1,
20 = 2
4+2
2.

Input

The first line of input contains integers 
X and 
Y, separated with a space (1 ≤ 
X ≤ 
Y ≤ 2
31−1). The next two lines contain integers 
K and 
B (1 ≤ 
K ≤ 20; 2 ≤ 
B ≤ 10).

Output

Output should contain a single integer — the amount of integers, lying between 
X and 
Y, being a sum of exactly 
K different integer degrees of 
B.

Sample

input output
15 2022
3

/*题意: 求一个区间的 degree进制的1的个数为k的数的个数思路:数位dp,一定要注意是1个个数为k  dp[i][j][k] 代表到达了i位的j进制还差k个1详细注意的地方写在了代码中*/#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define bug printf("hihi\n")#define eps 1e-8typedef long long ll;using namespace std;#define N 35int dp[33][15][33];int degree,k;int bit[N];int dfs(int pos,int degree,int t,bool bound){ if(t<0) return 0; if(pos==0) return t ? 0:1; if(!bound&&dp[pos][degree][t]>=0) return dp[pos][degree][t]; int up=bound ? min(bit[pos],1):1; int ans=0; for(int i=0;i<=up;i++) ans+=dfs(pos-1,degree,t-i,bound&&i==bit[pos]); //必须是bit[pos],不能是uo if(!bound) dp[pos][degree][t]=ans; return ans;}int solve(int x){ int i,j; int len=0; while(x) { bit[++len]=x%degree; x/=degree; } return dfs(len,degree,k,true);}int main(){ int i,j,le,ri; memset(dp,-1,sizeof(dp)); while(~scanf("%d%d",&le,&ri)) { scanf("%d%d",&k,°ree); printf("%d\n",solve(ri)-solve(le-1)); } return 0;}

转载地址:http://zyqtl.baihongyu.com/

你可能感兴趣的文章
人手一份核武器 - Hacking Team 泄露(开源)资料导览手册
查看>>
一起撸个朋友圈吧 点赞列表背景问题修复
查看>>
面试官,你再问我 Bit Operation 试试?
查看>>
PSV 3.60 固化升级到 3.68 破解完全攻略
查看>>
Android 路由框架
查看>>
当Kotlin遇见RxJava多数据源
查看>>
vue踩坑记- Cannot find module 'wrappy'
查看>>
【实操干货】KVM命令管理虚拟机与性能优化
查看>>
前端架构思想:聚类分层
查看>>
如何使用Thinkphp搭建商城系统(一)
查看>>
网易云副总经理陈谔:平台+场景化塑造差异优势
查看>>
Java架构师最关键三个思维转变方式
查看>>
OpenGL Android课程四:介绍纹理基础
查看>>
URL中“#” “?” &“”号的作用
查看>>
jQuery_渐隐式轮播效果插件封装
查看>>
以太坊2.0协议核心Beacon链详解
查看>>
机器学习资料合计(一)
查看>>
Redis 的基础数据结构(二) 整数集合、跳跃表、压缩列表
查看>>
webpack由浅入深——(webapck简易版)
查看>>
RxSwift(伪)实战 组内分享
查看>>