题意:求(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】的更多相关文章

  1. URAL 1057. Amount of Degrees(数位DP)

    题目链接 我看错题了...都是泪啊,不存在3*4^2这种情况...系数必须为1... #include <cstdio> #include <cstring> #include ...

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

  3. Ural 1057 Amount of Degrees

    Description 问[L,R]中有多少能表示k个b次幂之和. Sol 数位DP. 当2进制时. 建出一个二叉树, \(f[i][j]\) 表示长度为 \(i\) 有 \(j\) 个1的个数. 递 ...

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

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

  5. 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 ...

  6. URAL 1057 Amount of Degrees (数位DP,入门)

    题意: 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的,B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足了要求:  17 = 24+2 ...

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

  8. 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 ...

  9. ural 1057Amount of Degrees ——数位DP

    link:http://acm.timus.ru/problem.aspx?space=1&num=1057 论文: 浅谈数位类统计问题  刘聪 #include <iostream&g ...

随机推荐

  1. docker从零开始(三)服务初体验docker compose

    决条件 安装Docker 1.13或更高版本. 获取Docker Compose.在适用于Mac的Docker和适用于Windows的Docker上,它已预先安装,因此您可以随意使用.在Linux系统 ...

  2. mysql:functional dependency

    0down vote First, a functional dependency in the form A->B means that, given one value for A, we ...

  3. Bringing up interface eth0: Determining if ip address 10.109.67.81 is already in use for device eth0...

    重启网卡出现提示: Bringing up interface eth0:  Determining if ip address 10.109.67.81 is already in use for ...

  4. VMware vCenter Server安装与配置

    预先准备好安装包 ESXI6    VMware-VMvisor-Installer-6.0.0.update01-3073146.x86_64.iso VC        VMware-VIMSet ...

  5. python 去掉所有空白字符【解决】

    今天用python从access数据库读取内容,组合成sql语句时,空白字符把我给搞疯了.... 所幸找到了一个好办法: ''.join(s.split())

  6. HBASE启动失败,Failed construction of Master: class org.apache.hadoop.hbase.master.HMaster

    Master日志错误:2015-12-02 06:34:32,394 ERROR [main] master.HMasterCommandLine: Master exitingjava.lang.R ...

  7. HDU 多校1.3

    Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. tensorflow-gpu 使用的常见错误

    这篇博客会不定期整理我在 tensorflow 中出现的问题和坑. 1. CUDA_ERROR_OUT_OF_MEMORY: tensorflow 在执行过程中会默认使用全部的 GPU 内存,给系统保 ...

  9. gcc与gdb的使用

    1.gcc/g++编译过程: gcc/g++的编译格式: gcc [option][filename]... g++ [option][filename]... 1)processing:预处理过程, ...

  10. 1090: MTM (费用流)

    1090: MTM Time Limit:3000/1000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/Others)Total S ...