LOJ10163 Amount of Degrees
题目描述
求给定区间 [X,Y] 中满足下列条件的整数个数:这个数恰好等于 KK 个互不相等的 BB 的整数次幂之和。例如,设 X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意
输入格式
第一行包含两个整数 X 和 Y,接下来两行包含整数 K 和 B。
输出格式
只包含一个整数,表示满足条件的数的个数。
样例
样例输入
15 20
2
2
样例输出
3
数据范围与提示
对于全部数据,1≤X≤Y≤2^31−1,1≤K≤20,2≤B≤10。
______________________________________________________________________________________________
数位动归
一类区间统计问题,区间较大,无法用暴力求解或组合数学求解。
常见为求区间内满足某类条件的X进制数的个数。条件往往与数位有关。
此题:
首先,区间具有相减的性质。count[i...j]=count[ 0...j ] - count[ 0...i-1 ]。
这样问题就变成了0到i的x进制数有多少个满足条件。
因为是互不相等的k进制数,所以,转成k进制后,每个位上要么是0要么是1。
这样f[i][j]表示长度I的2进制数,有j个1的种类
f[i][j]=f[i-1][j]+f[i-1][j-1]
______________________________________________________________________________________________
1 #include<bits/stdc++.h>
2 using namespace std;
3 int x,y,k,b;
4 int wei[32];
5 int f[32][32];
6 void prech(int &x,int b)
7 {
8 int js=0;
9 while(x>0)
10 {
11 wei[++js]=x%b;
12 x/=b;
13 }
14 while(js>0)
15 {
16 if(wei[js]==1)x^=1<<(js-1);
17 else if(wei[js]>1)
18 {
19 for(int i=js;i>0;--i)x^=1<<(i-1);
20 break;
21 }
22 --js;
23 }
24 }
25 void dp()
26 {
27 f[0][0]=1;
28 for(int i=1;i<=31;++i)
29 {
30 f[i][0]=f[i-1][0];
31 for(int j=1;j<=i;++j)f[i][j]=f[i-1][j]+f[i-1][j-1];
32 }
33 }
34 int work(int x,int k)
35 {
36 int js=0,ans=0;
37 for(int i=31;i>0;--i)
38 {
39 if(x&(1<<i))
40 {
41 ++js;
42 if(js>k)break;
43 x=x^(1<<i);
44 }
45 if((1<<(i-1))&x)ans+=f[i-1][k-js];
46 }
47 if(js+x==k)ans++;
48 return ans;
49 }
50 int main()
51 {
52 scanf("%d%d%d%d",&x,&y,&k,&b);
53 x--;
54 prech(x,b);prech(y,b);
55 dp();
56 cout<<work(y,k)-work(x,k);
57 return 0;
58 }
LOJ10163 Amount of Degrees的更多相关文章
- 【数位DP】[LOJ10163]Amount of Degrees
发现自己以前对数位DP其实一窍不通... 这题可以做一个很简单的转换:一个数如果在$b$进制下是一个01串,且1的个数恰好有k个,那么这个数就是合法的(刚开始没判断必定是01串,只判断了1的个数竟然有 ...
- [TimusOJ1057]Amount of Degrees
[TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...
- 一本通1585【例 1】Amount of Degrees
1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...
- Timus Online Judge 1057. Amount of Degrees(数位dp)
1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the am ...
- [ACM] ural 1057 Amount of degrees (数位统计)
1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the am ...
- Ural Amount of Degrees(数位dp)
传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...
- 【算法•日更•第十二期】信息奥赛一本通1585:【例 1】Amount of Degrees题解
废话不多说,直接上题: 1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB提交数: 130 通过数: 68 [ ...
- [ural1057][Amount of Degrees] (数位dp+进制模型)
Discription Create a code to determine the amount of integers, lying in the set [X; Y] and being a s ...
- URAL 1057 Amount of Degrees (数位dp)
Create a code to determine the amount of integers, lying in the set [X;Y] and being a sum of exactly ...
随机推荐
- 这一次,彻底理解XSS攻击
希望读完本文大家彻底理解XSS攻击,如果读完本文还不清楚,我请你吃饭慢慢告诉你~ 话不多说,我们进入正题. 一.简述 跨站脚本(Cross-site scripting,简称为:CSS, 但这会与层叠 ...
- spring 切面织入报错:java.lang.ClassCastException: com.sun.proxy.$Proxy7 cannot be cast to...
报这个错,只有一个原因,就是转化的类型不对. 接口过父类的子类,在强制转换的时候,一定要用接口父类来定义. 代码示例: package com.luoluo.dao.impl; import java ...
- 1.简单使用两片74HC595实现动态显示数码管
本篇文章主要是讲解如何简单示用74HC595,更具体的讲解请移步 https://www.cnblogs.com/lulipro/p/5067835.html#undefined 这篇文章讲解的更加详 ...
- mysql基础之double,float长度标度定义
MySQL类型float double decimal的区别 float数值类型用于表示单精度浮点数值,而double数值类型用于表示双精度浮点数值,float和double都是浮点型,而decima ...
- LockSupport的深入浅出
public static void main(String[] args)throws Exception { final Object obj = new Object(); Thread A = ...
- vue的绑定属性v-bind
v-bind的简略介绍 v-bind用于绑定一个或多个属性值,或者向另一个组件传递props值.目前,个人所用之中,更多的是使用于图片的链接src,a标签中的链接href,还有样式以及类的一些绑定,以 ...
- LOG_PATH_IS_UNDEFINED
问题: SpringBoot + LogBack 写日志,除了正常的日志之外,程序跑起来后会在项目根目录多生成一个 LOG_PATH_IS_UNDEFINED 的文件夹,我的配置是以下: applic ...
- Hive日期函数总结(转学习使用)
一.时间戳函数 1.获取当前时区的UNIX时间戳:select unix_timestamp(); 2.将指定时间转为UNIX时间戳: select unix_timestamp('2012-03-0 ...
- SparkSql自定义数据源之读取的实现
一.sparksql读取数据源的过程 1.spark目前支持读取jdbc,hive,text,orc等类型的数据,如果要想支持hbase或者其他数据源,就必须自定义 2.读取过程 (1)sparksq ...
- 修改postman工具的代码生成工具让它锦上添花
@font-face { font-family: octicons-link; src: url("data:font/woff;charset=utf-8;base64,d09GRgAB ...