[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的个数. 递 ...
随机推荐
- FIFA halts 2026 bids amid scandal 国际足联在丑闻期间停止2026年足球世界杯申请
FIFA halts 2026 bids amid scandal 国际足联在丑闻期间停止2026年足球世界杯申请 But official insists 2018 Cup will stay in ...
- VM安装linux
看图简单流程即可.注意磁盘空间至少30G,实用oracle数据库时需要更大,可以后期增加. 静待安装完成即可.一定记得创建的用户名及密码,及root用户的密码.
- pickle模块简单使用
import pickle with open("school_info","wb") as school: user_input = str(input(&q ...
- mixin设计模式
mixin可以轻松被一个子类或者一组子类继承,目的是函数复用.在js中,我们可以将继承MiXin看作为一种通过扩展收集功能的方式. e.mixin = function(t) { for (var i ...
- 微软.NET序列化格式
官方文档 https://msdn.microsoft.com/en-us/library/cc236844.aspx 对比 http://www.codeproject.com/Articles/3 ...
- OWIN support for the Web API 2 and MVC 5 integrations in Autofac
Currently, in the both the Web API and MVC frameworks, dependency injection support does not come in ...
- Python之with语句
Python之with语句 在Python中,我们在打开文件的时候,为了代码的健壮性,通常要考虑一些异常情况,比如: try: ccfile = open('/path/data') content ...
- Lua 之string库
标准string库 基础字符串函数 string.len(s) 返回一个字符串的长度,例如 string.rep(s, n) 返回一个新的字符串,该字符串是参数s重复n次得到的结果,例如 )) -- ...
- C#通用类型转换 Convert.ChangeType
]; object innerValue = ChangeType(value, innerType); return Activator.CreateInstance ...
- LoadScript
function loadScripts(urls, callback) { if (typeof (urls) === "string"){ urls = [urls]; } v ...