ural1057 Amount of Degrees
这题有一点小坑点 就是AX^B A只能为0或者1 ,剩下的就比较好做的了。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL dp[][][];
int d[];
LL dfs(int i,int e,int k,int b)
{
if(i==-)
return k==;
if(!e&&dp[i][k][b] != -) return dp[i][k][b];
int mk = e?d[i]:;
int ans = ;
mk = min(,mk);
for(int j = ;j <= mk ;j++)
{
if(k-j>=)
{
ans+=dfs(i-,e&&j==d[i],k-j,b);
}
}
return e?ans:dp[i][k][b] = ans;
}
LL cal(int x,int k,int b)
{
int g = ;
while(x)
{
d[g++] = x%b;
x/=b;
}
return dfs(g-,,k,b);
}
int main()
{
int x,y,k,b;
memset(dp,-,sizeof(dp));
while(cin>>x>>y)
{
cin>>k>>b;
cout<<cal(y,k,b)-cal(x-,k,b)<<endl;
}
return ;
}
ural1057 Amount of Degrees的更多相关文章
- [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 ...
- Ural1057. Amount of Degrees 题解 数位DP
题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...
- URAL1057. Amount of Degrees(DP)
1057 简单的数位DP 刚开始全以2进制来算的 后来发现要找最接近x,y值的那个基于b进制的0,1组合 #include <iostream> #include<cstdio&g ...
- Ural1057 - Amount of Degrees(数位DP)
题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...
- ural1057 Amount of degrees 位数统计
#include <iostream> #include <string> using namespace std; ][]; void init(){ f[][] =; ;i ...
- [TimusOJ1057]Amount of Degrees
[TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...
- 一本通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 ...
随机推荐
- P1311 选择客栈
开始写了一个O(n3)的算法,只得了60,后来思考(找题解),得到了一个O(nk)的算法 其实就是一种预处理的思想,对于每一个客栈而言,只要我们预处理出他前面可以匹配的客栈数量,就可以了. 所以我们记 ...
- json解析jackson ,Gson,等知识总结
相关资料链接: Java构造和解析json数据的两种方法详解 java解析json Android网络之数据分析---使用Google Gson 解析Json数据 使用jackson在java中处理j ...
- tableView主从表在storyboard连线是 Selcetion Segue和Accessory Action的区别
当按住Ctorl这样连线时会出现,当选择Selection Segue下面的push时,点击cell的任何位置都会跳转到下一个tableView,当选择Accessory Action的下面的push ...
- MongoDB安装并设置为windows服务以使其开机自启
在MongoDB的官方下载windows平台的压缩zip文件,地址:https://www.mongodb.org/dr/fastdl.mongodb.org/win32/mongodb-win32- ...
- Spring mvc 下Ajax获取JSON对象问题 406错误
我在学习springmvc过程中(我的项目是配置的后缀是.html),从controller返回对象. 如果我不使用 mvc-annotation-driver,而是手动配置,AnnotationMe ...
- 使用Xcode6和IOS8SDK以后遇到的问题
定位.苹果在IOS8里面修改了定位授权协议,也就意味着你原来的app在ios8上很可能无法定位.目前最好的办法就是在app启动的时候调用IOS8的定位授权API来获取用户的授权,这样就不要在其他地方做 ...
- git如何使用 svn如何使用
git和svn是2款常用的版本控制系统. git 的功能: 1.从服务器上克隆完整的Git仓库(包括代码和版本信息)到单机上. 也就是说自己机器上有一个git仓库. 这和svn是不同的,svn是没有本 ...
- 《30天自制操作系统》16_day_学习笔记
harib13a: 今天我们要继续折腾多任务,任务的高效管理是操作系统的一个重要的任务.在今天,我们将为系统创建更加完善的任务管理系统,其中包括优先级,任务等级等. 1.任务管理结构体 #define ...
- Leetcode: Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- JDBC增删改查,PreparedStatement和Statement的区别
此篇是在上一篇的基础上使用PreparedStatement对象来实现JDBC增删改查的 具体工具类JDBCTools和实现类和配置文件在上一篇Statement对象实现的时候有写. 上一篇地址htt ...