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 amount of integers, lying in the set [X;Y] and being a sum of exactlyK 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. InputThe 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). OutputOutput 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.
Sample
|
/*
题意: 求一个区间的 degree进制的1的个数为k的数的个数
思路:数位dp,一定要注意是1个个数为k dp[i][j][k] 代表到达了i位的j进制还差k个1 详细注意的地方写在了代码中
*/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map> #define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1) #define bug printf("hihi\n") #define eps 1e-8 typedef long long ll; using namespace std; #define N 35 int dp[33][15][33]; int degree,k;
int bit[N]; int dfs(int pos,int degree,int t,bool bound)
{
if(t<0) return 0;
if(pos==0) return t ? 0:1;
if(!bound&&dp[pos][degree][t]>=0) return dp[pos][degree][t];
int up=bound ? min(bit[pos],1):1;
int ans=0;
for(int i=0;i<=up;i++)
ans+=dfs(pos-1,degree,t-i,bound&&i==bit[pos]); //必须是bit[pos],不能是uo
if(!bound) dp[pos][degree][t]=ans;
return ans;
} int solve(int x)
{
int i,j;
int len=0;
while(x)
{
bit[++len]=x%degree;
x/=degree;
}
return dfs(len,degree,k,true);
} int main()
{
int i,j,le,ri;
memset(dp,-1,sizeof(dp)); while(~scanf("%d%d",&le,&ri))
{
scanf("%d%d",&k,°ree);
printf("%d\n",solve(ri)-solve(le-1));
}
return 0;
}
Timus Online Judge 1057. Amount of Degrees(数位dp)的更多相关文章
- URAL 1057. Amount of Degrees(数位DP)
题目链接 我看错题了...都是泪啊,不存在3*4^2这种情况...系数必须为1... #include <cstdio> #include <cstring> #include ...
- [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 ...
- Ural1057 - Amount of Degrees(数位DP)
题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...
- [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
Description 问[L,R]中有多少能表示k个b次幂之和. Sol 数位DP. 当2进制时. 建出一个二叉树, \(f[i][j]\) 表示长度为 \(i\) 有 \(j\) 个1的个数. 递 ...
- 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 ...
- ural 1057 Amount of degrees 【数位dp】
题意:求(x--y)区间转化为 c 进制 1 的个数为 k 的数的出现次数. 分析:发现其满足区间减法,所以能够求直接求0---x 的转化为 c 进制中 1 的个数为k的数的出现次数. 首先用一个数组 ...
- URAL 1057 Amount of Degrees (数位DP,入门)
题意: 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的,B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足了要求: 17 = 24+2 ...
- ural 1057Amount of Degrees ——数位DP
link:http://acm.timus.ru/problem.aspx?space=1&num=1057 论文: 浅谈数位类统计问题 刘聪 #include <iostream&g ...
随机推荐
- times、 time、clock函数说明
sysconf( _SC_CLK_TCK ) 功能 获取系统的 时钟滴答的频率. clock_gettime() clock()返回的是各个线程运行cpu时间的和, 返回值一直都是0. 定义函数: ...
- Win10系统激活工具失败错误0xC004C003解决方法
用了几个WIN10的激活工具 都提示 错误0xC004C003 都原因就是这些CDKEY都被拉入了黑名单 鼠标左击屏幕左下角WIN图标,直接输入cmd,在弹出的 命令提示符 右击 以管理员运行(因为 ...
- (1) Flutter android studio安装
Flutter由两部分组成 Flutter引擎和Flutter框架 Flutter引擎由C++编写,在android上通过NDK编译,在ios上通过llvm编译 Flutter框架由dart编写 1. ...
- HDU 5969 最大的位或【贪心/按位或/思维】
链接 最大的位或 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...
- Java 反射调用的一种优化
写一些Java框架的时候,经常需要通过反射get或者set某个bean的field,比较普通的做法是获取field后调用java.lang.reflect.Field.get(Object),但每次都 ...
- Codeforces 785E Anton and Permutation(分块)
[题目链接] http://codeforces.com/contest/785/problem/E [题目大意] 一个1到n顺序排列的数列,每次选择两个位置的数进行交换,求交换后的数列的逆序对数 [ ...
- Mybatis通过ID查询 && 通过name模糊查询
接上篇:Mybatis环境搭建 在搭建环境时已经有了mapper和sqlMapConfig 1,数据库建表 prompt PL/SQL Developer import file prompt Cre ...
- Inno Setup入门(十五)——Inno Setup类参考(1)
Inno setup脚本能够支持许多的类,这些类使得安装程序的功能得到很大的加强,通过对这些类的使用,将会创建出许多让人惊奇的安装程序,下面开始类的学习. 创建自定义向导页 自定义向导页需要在Init ...
- 如何提高码农产量,基于ASP.NET MVC的敏捷开发框架之移动端开发随笔二
前言 在前一篇文章中我已经做过开篇,接下来的随笔会详细讲一下我们的开发框架是如何实现的,专业的事由专业的人来讲,以后就由我们的高级码农小李英文名查尔斯和他的师父厂长(因为姓陈,酷爱摄影,我们的文艺片都 ...
- sql获取汉字的拼音首字母的函数
ql获取汉字的拼音首字母 if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and ...