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 ...
随机推荐
- libev 学习使用
libev 简单的I/O库. a high performance full featured event loop written in c libev 的大小也比 libevent 小得多并且自 ...
- JavaWEB开发框架:Shiro
通过了三个月的实习,在javaWEB开发的过程当中,学习到了一些新的知识,特此记录一下学习到的一种新的WEB开发当中常用的用户认证和授权的安全框架,Shiro. 首先,要先知道shiro这个框架主要在 ...
- HDU 1181.变形课-并查集
变形课 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submis ...
- Ubuntu 14.04 安装JDK 8
1.安装JDK,参考 1.下载 JDK 8 从http://www.oracle.com/technetwork/java/javasebusiness/downloads/选择下载JDK的最新版本 ...
- Wannafly挑战赛17 A 走格子【矩阵行走/模拟】
[链接]:A [分析]:可以设置方向数组和标记数组.当不合法(越界/访问过)就转向,转向可以用now=(now+1)%4 [代码]: #include <bits/stdc++.h> #d ...
- SDL安装小结
SDL是一个基于C的简易实现,安装过程中也多亏了,各位大神的助攻,这里简单mark一下遇到的问题,以备查找: 关于VS的版本:目前文档里确定支持的VS为2008到2013,我的VS是2013,2015 ...
- [BZOJ 1143] 祭祀river
Link:https://www.lydsy.com/JudgeOnline/problem.php?id=1143 Solution: 一道最长反链的模板题 由Dilworth定理可知:最小链覆盖数 ...
- Problem K: 数字菱形
#include<stdio.h> int main() { int n,i,j,k,t,x,q,p; while(scanf("%d",&n)!=EOF) ; ...
- CLR探索系列:Windbg+SOS动态调试分析托管代码
http://blog.csdn.net/garyye/article/details/4788070 在使用VS进行托管应用程序的调试的时候,有的时候总感觉有些力不从心.譬如查看一个托管堆或者计 ...
- 如何设断点????-----使用WinDbg调试SQL Server查询
http://www.cnblogs.com/woodytu/p/4665427.html http://www.sqlservercentral.com/blogs/aschenbrenner/20 ...