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 ...
随机推荐
- python(1)
1.适配中文 #coding-utf-8 #coding: utf-8 2.格式化输出,此时的转义字符不能用\,只能用% print 'growth rate : %d \%' % 7 5 3 Tru ...
- 土壤湿度传感器YL69使用
1.电源:3.3V ~ 5V 2.获取湿度信息的方式(2种可同时使用): 从传感器的D0引脚:土壤湿度大于某个阈值,则D0输出0,否则输出1 从传感器的A0引脚:获取到模拟量,更加精确.土壤湿度越大, ...
- python 多线程就这么简单(续)
之前讲了多线程的一篇博客,感觉讲的意犹未尽,其实,多线程非常有意思.因为我们在使用电脑的过程中无时无刻都在多进程和多线程.我们可以接着之前的例子继续讲.请先看我的上一篇博客. python 多线程就这 ...
- Maintaining Your Signing Identities and Certificates 维护你的签名标识和证书
Code signing your app lets users trust that your app has been created by a source known to Apple and ...
- Java 并发性和多线程
一.介绍 在过去单 CPU 时代,单任务在一个时间点只能执行单一程序.之后发展到多任务阶段,计算机能在同一时间点并行执行多任务或多进程.虽然并不是真正意义上的“同一时间点”,而是多个任务或进程共享一个 ...
- Velocity模板引擎语法
Velocity 模板引擎介绍 Velocity是一个基于java的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来引用由java ...
- Linux系统编程--文件IO操作
Linux思想即,Linux系统下一切皆文件. 一.对文件操作的几个函数 1.打开文件open函数 int open(const char *path, int oflags); int open(c ...
- enum使用
新建一个.h文件 typedef enum { type1 = 1, type2 = 2 };
- Latex 分段函数
Latex里面分段函数的输入: \begin{equation} P_{r-j}= \begin{cases} 0&\mbox{if $r-j$ is odd}\\ ...
- stl 比较和boost LessThanComparable
C++ STL的几种常用“比较”概念简述 在C++的现行标准(C++ 98)中,由于没有类似“接口”这样的东西,我们在泛型编程时往往只能对模板类型作一些假设,要求其符合某个需求清单,也就是属于某个 ...