Ural Amount of Degrees(数位dp)
Amount of Degrees
Memory limit: 64 MB
Description
18 = 24+21,
20 = 24+22.
Input
Output
Sample
| input | output |
|---|---|
15 20 |
3 |
解题思路
题意:

思路:



#include<iostream>
#include<string>
using namespace std;
int f[32][32]; int change(int x, int b)
{
string s;
do
{
s = char('0' + x % b) + s;
x /= b;
}
while (x > 0);
for (int i = 0; i < s.size(); ++i)
if (s[i] > '1')
{
for (int j = i; j < s.size(); ++j) s[j] = '1';
break;
}
x = 0;
for (int i = 0; i < s.size(); ++i)
x = x | ((s[s.size() - i - 1] - '0') << i); //或运算,在此相当于加法
return x;
} void init()//预处理f
{
f[0][0] = 1;
for (int i = 1; i <= 31; ++i)
{
f[i][0] = f[i - 1][0];
for (int j = 1; j <= i; ++j) f[i][j] = f[i - 1][j] + f[i - 1][j - 1];
}
} int calc(int x, int k) //统计[0..x]内二进制表示含k个1的数的个数
{
int tot = 0, ans = 0; //tot记录当前路径上已有的1的数量,ans表示答案
for (int i = 31; i > 0; --i)
{
if (x & (1 << i)) //该位上是否为1
{
++tot;
if (tot > k) break;
x = x ^ (1 << i); //将这一位置0
}
if ((1 << (i - 1)) <= x)
{
ans += f[i - 1][k - tot];
}
}
if (tot + x == k) ++ans;
return ans;
} int main()
{
int x, y, k, b;
cin >> x >> y >> k >> b;
x = change(x, b);
y = change(y, b);
init();
cout << calc(y, k) - calc(x - 1, k) << endl;
return 0;
}
Ural Amount of Degrees(数位dp)的更多相关文章
- Ural1057 - Amount of Degrees(数位DP)
题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...
- URAL 1057. Amount of Degrees(数位DP)
题目链接 我看错题了...都是泪啊,不存在3*4^2这种情况...系数必须为1... #include <cstdio> #include <cstring> #include ...
- [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 1057Amount of Degrees ——数位DP
link:http://acm.timus.ru/problem.aspx?space=1&num=1057 论文: 浅谈数位类统计问题 刘聪 #include <iostream&g ...
- [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 ...
- 基础数位DP小结
HDU 3555 Bomb dp[i][0] 表示含 i 位数的方案总和. sp[i][0] 表示对于位数为len 的 num 在区间[ 10^(i-1) , num/(10^(len-i)) ] 内 ...
- Ural1057. Amount of Degrees 题解 数位DP
题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...
- 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 ...
- 2018.09.07 Amount of degrees(数位dp)
描述 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和. 例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 17 = 24+20, ...
随机推荐
- Codeforces 1163D Mysterious Code(AC自动机+DP)
用 AC自动机 来做有点想不到,捞一手就是学一手. 设 dp[ i ][ j ] 表示字符串 c 中的第 i 位到字典树上节点 j 的最大值是多少, word[ j ] 表示在节点 j 下对答案修改的 ...
- js页面加载的几种方式的速度: window.onload、 $(window).load、 $(function(){})、 $(document).ready(function () {})、onload=‘asd()’
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- JDK 8 中Stream流中的去重的方法
JDK 8 中Stream流中去重的方法 1.简单的去重,可以使用distinct()方法去重,该方法是通过比较equals和hashcode值去去重, 2.复杂的去重, 例如,在一个JavaBean ...
- ajaxSubmit 实现图片上传 SSM maven
文件上传依赖: <!-- 文件上传组件 --> <dependency> <groupId>commons-fileupload</groupId> & ...
- jQuery学习总结02-筛选
一.筛选 1.eq(index|-index) 说明:获取当前链式操作中第N个jQuery对象,返回jQuery对象,类似的有get(index),不过get(index)返回的是DOM对象 示例: ...
- Tomcat 保存镜像实战操作( 目录挂载方法 )
查看数据保存的位置 docker inspect --format='{{.Mounts}}' mxg_tomcat 宿主机数据保存在 /usr/local/project , 将此路径数据备份在 b ...
- 苹果账号需要的邓白氏D-U-N-S编码更新信息最新方法,官方已不受理邮件
公司从上海搬迁到深圳,公司名称相应变更,但之前注册的苹果开发者账号上的名字还是就的,尝试在后台提交更新申请,官方给了邮件,要求邮件提交证明材料,证明材料提交后,苹果又反馈和邓白氏的资料不匹配,要求先修 ...
- mysql 导出表中数据为excel的xls格式文件
需求: 利用mysql客户端导出数据库中数据,以便进行分析,统计. 解决命令: 在windos命令行(linux同理)下,用如下命令即可: mysql -hlocalhost -uroot -ppas ...
- [NOI2007]社交网络(最短路)
[NOI2007]社交网络 Description 在社交网络(socialnetwork)的研究中,我们常常使用图论概念去解释一些社会现象.不妨看这样的一个问题. 在一个社交圈子里有n个人,人与人之 ...
- php $_SERVER 中的 QUERY_STRING和REQUEST_URI
index.php <?php print_r($_GET); parse_str($_SERVER['QUERY_STRING'],$get); print_r($get); print_r( ...