题意:求(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. js排序(转载)

    原文地址:http://blog.csdn.net/wzwlln/article/details/6187732#plain sort(sortfunction)为javascript的数组对象(Ar ...

  2. ITerms2在mac系统下的安装和配色,并和go2shell关联

    官网下载并安装 拖到应用文件夹使其在应用中展示 熟悉快捷键 无鼠标复制: cmd+f:查找首字母,再按tab向右选择词汇,按shift+tab向左选择词汇 分屏 cmd+d:垂直分屏 cmd+shif ...

  3. 关于oracle的sqlplus的另一些小技巧

    执行脚本的命令在上一节已经讲过,不再重复. sqlplus user/password@ip:port/servicename @/path/sqltest.sql; sqltest的内容及注释: - ...

  4. AC日记——由乃与大母神原型和偶像崇拜 洛谷 P3792

    由乃与大母神原型和偶像崇拜 思路: 逆元+线段树维护和+线段树维护平方和+线段树维护最大最小值: 代码: #include <bits/stdc++.h> using namespace ...

  5. [转]python dubbo接口测试

    转自:https://www.cnblogs.com/chunyanxu/p/8732734.html 会吐泡泡的鱼 博客园 首页 新闻 新随笔 联系 管理 订阅 随笔- 57  文章- 0  评论- ...

  6. [orangehrm] 安装问题集合

    Web server allows .htaccess files # 这一项检查不通过 解决: In conf/extra/httpd-vhosts.conf, add the line Allow ...

  7. (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) au ...

  8. [Codeforces 8D] Two Friends

    Brief Introduction: 有两人a.b,他们都在A点,a经过B点到C点,而b直接到C点.a走过的距离不超过la,b走过距离不超过lb,询问他们可能经过最长的公共距离. Algorithm ...

  9. [BZOJ 2756] 奇怪的游戏

    Link:https://www.lydsy.com/JudgeOnline/problem.php?id=2756 Algorithm: 比较新颖的题目 首先发现是对矩阵中相邻两数进行操作    & ...

  10. (转)unity web 缓存解决方案

    unity web 缓存解决方案 官方发布 web版限制五十M缓存,根据自己的经验绕了过去,解决了缓存的问题.带工程,带源代码.由于本人的水平也有限,是用JS来解决的,如果你还是没有头绪,可以购买来试 ...