ural 1057 Amount of degrees 【数位dp】
题意:求(x--y)区间转化为 c 进制 1 的个数为 k 的数的出现次数。
分析:发现其满足区间减法,所以能够求直接求0---x 的转化为 c 进制中 1 的个数为k的数的出现次数。
首先用一个数组f【i】【j】:表示前 i 位中有 j 位为 1 的个数。
能够通过方程 f【i】【j】 = f【i-1】【j】 + f【i-1】【j-1】来预处理出来。
对于要求的答案,我们能够借助树来求。
假如13 。2进制,有3个1 。转化为2进制 1101
能够借助于一个二进制的表示的树来求。
AC代码:
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <iostream>
#include <cmath>
using namespace std;
#define Del(a,b) memset(a,b,sizeof(a))
typedef long long LL;
const double esp = 1e-10;
const int N = 50;
int f[N][N]; //f[i][j] 前i个中选j个1的个数
void isit()
{
f[0][0] = 1;
for(int i=1;i<33;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 solve(int x,int k,int c)
{
vector<int> v;
while(x)
{
v.push_back(x%c);
x/=c;
}
int cnt = 0,ans = 0;
for(int i=v.size()-1;i>=0;i--)
{
if(v[i]==1) //为1,则依次求解
{
ans+=f[i][k-cnt];
cnt++;
if(cnt==k)
break;
}
else if(v[i]>1) //假如大于1的话。相当于全部的位有能够为1,所以直接求解跳出
{
ans += f[i+1][k-cnt];
break;
}
}
if(cnt==k)
ans++;
return ans;
}
int main()
{
isit();
int x,y,k,c;
while(~scanf("%d%d%d%d",&x,&y,&k,&c))
{
printf("%d\n",solve(y,k,c)-solve(x-1,k,c));
}
return 0;
}
ural 1057 Amount of degrees 【数位dp】的更多相关文章
- URAL 1057. Amount of Degrees(数位DP)
题目链接 我看错题了...都是泪啊,不存在3*4^2这种情况...系数必须为1... #include <cstdio> #include <cstring> #include ...
- [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 1057 Amount of Degrees
Description 问[L,R]中有多少能表示k个b次幂之和. Sol 数位DP. 当2进制时. 建出一个二叉树, \(f[i][j]\) 表示长度为 \(i\) 有 \(j\) 个1的个数. 递 ...
- Ural1057 - Amount of Degrees(数位DP)
题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...
- 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 ...
- URAL 1057 Amount of Degrees (数位DP,入门)
题意: 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的,B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足了要求: 17 = 24+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 ...
- 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 ...
- ural 1057Amount of Degrees ——数位DP
link:http://acm.timus.ru/problem.aspx?space=1&num=1057 论文: 浅谈数位类统计问题 刘聪 #include <iostream&g ...
随机推荐
- C++类中引用成员和常量成员的初始化(初始化列表)
如果一个类是这样定义的: Class A { public: A(int pram1, int pram2, int pram3); privite: int a; int &b; const ...
- HDU-5074
Hatsune Miku Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- servletcontext.getRealPath()
getRealPath方法已经不建议使用了: http://blog.csdn.net/lzynihao/article/details/8315796 另外:http://veryls.iteye. ...
- CSDN博客排名记录
截止今天,在CSDN的博客排名终于从"千里之外"变成具体的排名数字了.根据CSDN的规则,只有排名在20000以内才能显示具体的排名.从2015年5月11日开始写了第一篇博客.后来 ...
- selenium3+python自动化50-环境搭建(firefox)【转载】
前言 有不少小伙伴在安装selenium环境后启动firefox报错,因为现在selenium升级到3.0了,跟2.0的版本还有有一点区别的. 安装环境过程中主要会遇到三个坑: 1.'geckodri ...
- (五)cobbler自定义系统安装
注意:需要提前获取到物理机对应的网卡的MAC地址,例如我这里使用虚拟机进行演示 cobbler system add --name=linux-node2.com --mac=00:50:56:22: ...
- Codeforces 538 A. Cutting Banner-substr()函数字符串拼接
A. Cutting Banner time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 【动态规划】矩形嵌套 (DGA上的动态规划)
[动态规划]矩形嵌套 时间限制: 1 Sec 内存限制: 128 MB提交: 23 解决: 9[提交][状态][讨论版] 题目描述 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a, ...
- 【进制转换】CODEVS 1740 进制计算器
#include<cstdio> #include<iostream> #include<string> using namespace std; string s ...
- 微信小程序API·目录
网络 媒体 文件 数据缓存 位置 设备 界面 第三方平台 开放接口 数据 更新 多线程 监控 调试接口 日志