[TimusOJ1057]Amount of Degrees
[TimusOJ1057]Amount of Degrees
试题描述
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的更多相关文章
- 一本通1585【例 1】Amount of Degrees
1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...
- 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 ...
- [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 Amount of Degrees(数位dp)
传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...
- 【算法•日更•第十二期】信息奥赛一本通1585:【例 1】Amount of Degrees题解
废话不多说,直接上题: 1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB提交数: 130 通过数: 68 [ ...
- [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)
Create a code to determine the amount of integers, lying in the set [X;Y] and being a sum of exactly ...
- Ural1057. Amount of Degrees 题解 数位DP
题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...
- Ural 1057 Amount of Degrees
Description 问[L,R]中有多少能表示k个b次幂之和. Sol 数位DP. 当2进制时. 建出一个二叉树, \(f[i][j]\) 表示长度为 \(i\) 有 \(j\) 个1的个数. 递 ...
随机推荐
- Android onLowMemory()和onTrimMemory()
1. OnLowMemory OnLowMemory是Android提供的API,在系统内存不足,所有后台程序(优先级为background的进程,不是指后台运行的进程)都被杀死时,系统会调用OnLo ...
- c#.net WinForm 线程内 调用窗体控件
richTextBox1.BeginInvoke(new EventHandler(delegate { richTextBox1.AppendText("正在提交服务器..\r\n&quo ...
- lightbox图片展示效果
1.lightbox 头部导入: <script type="text/javascript" src="../Public/Js/prototype.js&quo ...
- ServletContext
1.为什么需要servletContext 需求1 需求2 --------------->解决之道servletContext servletContext 1.ServletC ...
- redis使用watch完成秒杀抢购功能(转)
redis使用watch完成秒杀抢购功能: 使用redis中两个key完成秒杀抢购功能,mywatchkey用于存储抢购数量和mywatchlist用户存储抢购列表. 它的优点如下: 1. 首先选用内 ...
- android自定义控件(1)-点击实现开关按钮切换
自定义控件的步骤.用到的主要方法: 1.首先需要定义一个类,继承自View:对于继承View的类,会需要实现至少一个构造方法:实际上这里一共有三个构造方法: public View (Contex ...
- 发布自己的包到Nuget上
1.首先下载Nuget.exe https://dist.nuget.org/index.html 2.设置环境变量 设置apikey nuget setApiKey <my_api_key& ...
- fedora23忘记root密码怎么办??
fedora23使用的是uefi, 不是 传统的grub 所以在编辑grub的时候, 跟以前的版本略有不同 最最重要的是: 在编辑启动条目的时候, 那个 linuxefi ... vmlinuz... ...
- linux脚本编程(shell)浅介 (转载)
linux脚本(shell)编程 啊,昨天上网看到一篇讲 linux/unix shell 的文章,想想自己最后写这东西也是一年前的事了,想想都快忘光了. 还是整理一下,做一次回顾,以后说不定还用得上 ...
- linux网络:常用命令(一)
1.ifconfig 可以查看Linux的网卡情况 ifconfig eth0 查看 eth0的信息 给一块网卡设置多个ip地址: ifconfig eth0:0 192.168.1.12 255. ...