Ural1057 - Amount of Degrees(数位DP)
题目大意
求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整
数次幂之和。例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意:

输入:第一行包含两个整数X和Y。接下来两行包含整数K和B。
输出:只包含一个整数,表示满足条件的数的个数。
数据规模:1 ≤ X ≤ Y ≤ 2^31
−1,1 ≤ K ≤ 20, 2 ≤ B ≤ 10。
题解
《浅谈数位类统计问题》的论问题~~~~~人生第一道数位DP,哈哈~~~O(∩_∩)O~~代码纯属抄袭~~~~
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
#define MAXN 35
int f[MAXN][MAXN];
void init()
{
f[0][0]=1;
for(int i=1;i<32;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 change(int x,int b)
{
int p[MAXN];
int ans=0;
while(x)
{
p[ans++]=x%b;
x/=b;
}
reverse(p,p+ans);
for(int i=0;i<ans;i++)
if(p[i]>1)
{
for(int j=i;j<ans;j++)
p[j]=1;
break;
}
for(int i=0;i<ans;i++)
x=x|(p[ans-i-1]<<i);
return x;
}
int cal(int x,int k)
{
int tot=0,ans=0;
for(int i=31;i>0;i--)
{
if(x&(1<<i))
{
tot++;
if(tot>k) break;
x=x^(1<<i);
}
if((1<<(i-1))<=x)
ans+=f[i-1][k-tot];
}
if(tot+x==k) ans++;
return ans;
}
int main()
{
init();
int x,y,k,b;
while(cin>>x>>y>>k>>b)
{
int X=change(x,b);
int Y=change(y,b);
cout<<cal(Y,k)-cal(X-1,k)<<endl;
}
return 0;
}
Ural1057 - Amount of Degrees(数位DP)的更多相关文章
- [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)
题目链接 我看错题了...都是泪啊,不存在3*4^2这种情况...系数必须为1... #include <cstdio> #include <cstring> #include ...
- Ural1057. Amount of Degrees 题解 数位DP
题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...
- URAL1057. Amount of Degrees(DP)
1057 简单的数位DP 刚开始全以2进制来算的 后来发现要找最接近x,y值的那个基于b进制的0,1组合 #include <iostream> #include<cstdio&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 ...
- ural1057 Amount of Degrees
链接 这题有一点小坑点 就是AX^B A只能为0或者1 ,剩下的就比较好做的了. #include <iostream> #include<cstdio> #include ...
- ural 1057Amount of Degrees ——数位DP
link:http://acm.timus.ru/problem.aspx?space=1&num=1057 论文: 浅谈数位类统计问题 刘聪 #include <iostream&g ...
- ural1057 Amount of degrees 位数统计
#include <iostream> #include <string> using namespace std; ][]; void init(){ f[][] =; ;i ...
- 数位dp总结
由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...
随机推荐
- 在VS中手工创建一个最简单的WPF程序
如果不用VS的WPF项目模板,如何手工创建一个WPF程序呢?我们来模仿WPF模板,创建一个最简单的WPF程序. 第一步:文件——新建——项目——空项目,创建一个空项目. 第二步:添加引用,Presen ...
- poj 3013 Big Christmas Tree Djistra
Big Christmas Tree 题意:图中每个节点和边都有权值,图中找出一颗树,树根为1使得 Σ(树中的节点到树根的距离)*(以该节点为子树的所有节点的权值之和) 结果最小: 分析:直接求出每个 ...
- 编译报错GLIBCXX_3.4.15 clock_gettime@@GLIBC_2.2
GLIBCXX_3.4.15 升级gcc,g++编译器 clock_gettime@@GLIBC_2.2 链接库时加-lrt
- 【一起学OpenFOAM】04 OpenFOAM的学习资源
OpenFOAM的学习资料并不多,个人猜测也许是与软件的类型有关系. 对于商用软件来讲,由于要占领市场,软件开发商自然是巴不得会用软件的人越多越好,因为他们卖的是软件,会用的人越多,软件卖得越好.他们 ...
- c# int? i = null
语法 T? 是 Nullable<T>的简写. Nullable<int> i = null; 等价于 int? i = null; 在Nullable赋值给非Nullable ...
- 关于 IIS 上的 Speech 设置
在之前的开发过程中,发现在 微软各个版本的Speech中(从sdk5.1 到 最新的 Speech PlatFarme V11),在本地可以生成音频文件,但是在IIS上却生成无法生成完整的文件. 调试 ...
- 备忘·添加SublimeText3右键菜单
因为用的sublimeText3是免安装版,打开未关联文件,略有麻烦,所以搜了一下,发现几种解决办法,其中INF文件的方法很喜欢,备份下 [Version] Signature="$Wind ...
- Java连接MySQl数据库实现代码
1. 获取数据库连接和查询代码 package connectionmysql; import java.sql.Connection; import java.sql.DriverManager; ...
- bzoj 3672: [Noi2014]购票 树链剖分+维护凸包
3672: [Noi2014]购票 Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 480 Solved: 212[Submit][Status][D ...
- CAN
CAN Introduction Features Network Topology(CANbus網路架構) MESSAGE TRANSFER(CAN通訊的資料格式) 1.DATA FRAME(資料通 ...