#include <iostream>
#include <string>
using namespace std; int f[][];
void init(){
f[][] =;
for(int i=;i<=;i++){
f[i][] = f[i-][];
for(int j=;j<=i;j++)
f[i][j] = f[i-][j]+f[i-][j-];
}
} int change(int x,int b){
string s;
while(x){
s = (char)(x%b+'')+s;
x = x/b;
}
for(int i=;i<s.size();i++)
if(s[i]>''){
for(int j=i;j<s.size();j++)
s[j] = '';
break;
}
x =;
for(int i=;i<s.size();i++){
x = x|((s[s.size()--i]-'')<<i);
}
return x;
} int cal(int x,int k){
int tot =,ans =;
for(int i=;i>;i--){
if(x&(<<i)){
tot++;
if(tot>k) break;
x = x^(<<i);
}
if((<<(i-))<=x){
ans += f[i-][k-tot];
}
}
if(tot + x==k) ans++;
return ans;
} int main()
{
init();
int x,y;
int k,b;
cin>>x>>y>>k>>b;
x= change(x,b);
y = change(y,b);
int resx = cal(x-,k);
int resy = cal(y,k);
cout<<resy-resx<<endl;
return ;
}

ural1057 Amount of degrees 位数统计的更多相关文章

  1. [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 ...

  2. [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 ...

  3. Ural1057. Amount of Degrees 题解 数位DP

    题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...

  4. Ural1057 - Amount of Degrees(数位DP)

    题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...

  5. ural1057 Amount of Degrees

    链接 这题有一点小坑点 就是AX^B  A只能为0或者1  ,剩下的就比较好做的了. #include <iostream> #include<cstdio> #include ...

  6. URAL1057. Amount of Degrees(DP)

    1057 简单的数位DP  刚开始全以2进制来算的 后来发现要找最接近x,y值的那个基于b进制的0,1组合 #include <iostream> #include<cstdio&g ...

  7. 一本通1585【例 1】Amount of Degrees

    1585: [例 1]Amount of Degrees 时间限制: 1000 ms         内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...

  8. Ural Amount of Degrees(数位dp)

    传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...

  9. [TimusOJ1057]Amount of Degrees

    [TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...

随机推荐

  1. const和readonly你真的懂吗?

    第二遍文章我打算把const和readonly的区别拿出来讲下,因为写代码这么久我都还没搞清楚这两者的区别,实在有点惭愧,所以这一次我打算搞清楚它. 定义 来看看MSDN的解释: readonly:r ...

  2. USACO Section 5.1 Fencing the Cows(凸包)

    裸的凸包..很好写,废话不说,直接贴代码. ----------------------------------------------------------------------------- ...

  3. day7_python学习笔记_chapter9_文件

    1. open(), file(), 作用完全相同 2. 语法: file_object = open(file_name, access_mode='r', buffering='-1') acce ...

  4. js调用ASP.NET打印代码

    第一步:添加下面的js <script type="text/javascript">           function printsetup() {        ...

  5. js中&& 和 ||

    原文链接:http://wenrunchang123.iteye.com/blog/1749802 a() && b()     1). 如果执行a() 返回true:那么执行b()并 ...

  6. 帝国cms中上一篇与下一篇个性化灵动标签调出

    这里的上下篇是用灵动标签制作,可以更为个性化 下一篇 <a href="<?phpecho $bqsr[titleurl];$next='true';?>"> ...

  7. perspective结合transform的3D效果

    http://css-tricks.com/almanac/properties/p/perspective/ 链接中讲了 perspective的两种用法及比较: 1.perspective:100 ...

  8. jquery submit()不能提交表单的解决方法

    <form id="form" method="get"> <input type="text" name="q ...

  9. openstack nova修改实例路径,虚拟磁盘路径

    #实例路径 --instances_path=$state_path/instances #日志的目录 --logdir=/var/log/nova #nova的目录 --state_path=/va ...

  10. 12.04 如何更专业的使用Chrome开发者工具

    顾名思义Chrome开发工具就是一个工具,它允许Web开发人员可以通过浏览器应用程序干预和操作Web页面,也可以通过这个工具调试和测试Web页面或Web应用程序.有了这个工具,你可以做很多有趣的事情: ...