[TimusOJ1057]Amount of Degrees

试题描述

Create a code to determine the amount of integers, lying in the set [X;Y] and being a sum of exactly K different integer degrees of B.
Example. Let X=15, Y=20, K=2, B=2. By this example 3 numbers are the sum of exactly two integer degrees of number 2:
17 = 24+20,
18 = 24+21,
20 = 24+22.

输入

The first line of input contains integers X and Y, separated with a space (1 ≤ X ≤ Y ≤ 231−1). The next two lines contain integers K and B (1 ≤ K ≤ 20; 2 ≤ B ≤ 10).

输出

Output should contain a single integer — the amount of integers, lying between X and Y, being a sum of exactly K different integer degrees of B.

输入示例


输出示例


数据规模及约定

见“输入

题解

就是看转换成 b 进制之后是不是只有 0 和 1 并且 1 的个数恰好等于 k。

行了,明白了题意,就没啥可说的了。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 35
#define maxk 25
int f[maxn][2][maxk], K, b; int num[maxn];
int sum(int x) {
int cnt = 0, tx = x;
while(x) num[++cnt] = x % b, x /= b;
int ans = 0, Cnt = 0;
for(int i = cnt; i; i--) {
for(int j = 0; j < min(2, num[i]); j++) ans += f[i][j][K-Cnt];
if(num[i] > 1){ Cnt = -1; break; }
Cnt += num[i];
}
ans += (Cnt == K);
return ans;
} int main() {
f[1][0][0] = 1; f[1][1][1] = 1;
for(int i = 1; i <= 32; i++)
for(int j = 0; j <= 1; j++)
for(int k = 0; k <= i; k++)
for(int x = 0; x <= 1; x++)
f[i+1][x][k+x] += f[i][j][k]; int l = read(), r = read(); K = read(); b = read();
printf("%d\n", sum(r) - sum(l - 1)); return 0;
}

[TimusOJ1057]Amount of Degrees的更多相关文章

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

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

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

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

  4. Ural Amount of Degrees(数位dp)

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

  5. 【算法•日更•第十二期】信息奥赛一本通1585:【例 1】Amount of Degrees题解

    废话不多说,直接上题: 1585: [例 1]Amount of Degrees 时间限制: 1000 ms         内存限制: 524288 KB提交数: 130     通过数: 68 [ ...

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

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

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

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

  9. Ural 1057 Amount of Degrees

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

随机推荐

  1. glade2支持C++代码的输出(2)

    今天更新了一个BaseObject的代码:BaseObject.002.zip 同时将glade2生成C++代码的代码进行了调整,基于2.12.2的补丁为:cpp_out_2.patch.tar.xz ...

  2. css008 给网页添加图片

    css008 给网页添加图片 1.            css和<img>标签       1.<img>标签是html的添加图片的标签,一般为: <img src=” ...

  3. MySQL的mysqldump工具的基本用法

    导出要用到MySQL的mysqldump工具,基本用法是:    shell> mysqldump [OPTIONS] database [tables]    如果你不给定任何表,整个数据库将 ...

  4. Linux下删除命令

    linux删除目录很简单 使用rm -rf命令即可.直接rm就可以了,不过要加两个参数-rf 即:rm -rf 目录名字(警告:不作任何提示,且不可恢复,不要说没提醒哦!严重警告!!!)-r 就是向下 ...

  5. 简述frame、bounds、center

    frame是该视图在父视图坐标系统中的位置和大小.(参照父视图中的坐标系统) bounds是该视图在自身坐标系统中的位置和大小.(参照自身的坐标系统) center是该视图的中心点在父视图坐标系统中的 ...

  6. webservice报错Message part refundRequest was not recognized. (Does it exist in service WSDL?)

    最近在做一个支付的接口. 因为接口方使用webservice交互.  我只能去学习了下webservice 现在出了一个很古怪的问题~  我在请求他们url的时候, 返回给我找不到控制名错误 Mess ...

  7. android-获取当前屏幕尺寸信息

    方法有两种一: DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMet ...

  8. PPTP(Point to Point Tunneling Protocol),即点对点隧道协议。

    PPTP PPTP(Point to Point Tunneling Protocol),即点对点隧道协议.该协议是在PPP协议的基础上开发的一种新的增强型安全协议,支持多协议虚拟专用网(VPN),可 ...

  9. thinkphp-3

    有两种创建项目的方式: 一是用多个单入口文件, 一个入口文件对应着一个项目, 如前台/后台/会员中心等 二是用一个单入口, 创建项目分组 对于有多个入口文件的 情况, 配置文件的共享问题? 不管是前台 ...

  10. A simple Snippet in ST2

    Reference: http://web-design-weekly.com/2012/07/03/snippets-in-sublime-text-2/ A sample - cofirm (To ...