URAL1057. Amount of Degrees(DP)
简单的数位DP 刚开始全以2进制来算的 后来发现要找最接近x,y值的那个基于b进制的0,1组合
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define LL __int64
#define INF 1e11
LL dp[][],pp[][];
int g1,g2,p[<<];
void init()
{
int i,j;
for(i = ; i <= ; i++)
{
pp[i][] = ;
for(j = ; j <= ; j++)
{
pp[i][j] = pp[i][j-]*i;
if(pp[i][j]>INF)
break;
}
}
dp[][] = ;
dp[][] = ;
dp[][] = ;
for(i = ; i <= ; i++)
{
dp[i][] = ;
for(j =; j <= ; j++)
dp[i][j] = dp[i-][j-]+dp[i-][j];
}
}
void change(int x,int y,int b,int c1[],int c2[])
{
int di[],g=,i;
while(x)
{
di[++g] = x%b;
x/=b;
}
for(i = g ; i >= ;i--)
c1[i] = di[i];
g1 = g;
g = ;
while(y)
{
di[++g] = y%b;
y/=b;
}
for(i = g ; i >= ;i--)
c2[i] = di[i];
g2 = g;
}
LL find(int c[],int k,int len)
{
int i,j,o=;
LL sum=;
for(i = len ; i >= ; i--)
{
if(c[i]==) continue;
if(k>=o)
sum+=dp[i-][k-o];
o++;
}
if(o==k)
sum++;
return sum;
}
int main()
{
int x,y,k,b,j,i;
int c1[],c2[];
init();
scanf("%d%d%d%d",&x,&y,&k,&b);
if(b!=)
{
LL s=,x1=-,x2=-;
x--;
for(i = ; i <= (<<) ; i++)
{
s = ;
for(j = ; j <= ; j++)
if(i&(<<j))
{
s+=pp[b][j];
}
if(x1==-&&s>x)
x1 = i-;
if(s>y)
{
x2 = i-;
break;
}
}
for(j = ; j >= ; j--)
if(x1&(<<j))
{
c1[j+] = ;
if(!g1)
g1 = j+;
}
else
c1[j+] = ;
for(j = ; j >= ; j--)
if(x2&(<<j))
{
c2[j+] = ;
if(!g2)
g2 = j+;
}
else
c2[j+] = ;
}
else
change(x-,y,b,c1,c2);
LL s1 = find(c1,k,g1);
LL s2 = find(c2,k,g2);
printf("%I64d\n",s2-s1);
return ;
}
URAL1057. Amount of Degrees(DP)的更多相关文章
- Ural1057. Amount of Degrees 题解 数位DP
题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...
- [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)
题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...
- ural1057 Amount of Degrees
链接 这题有一点小坑点 就是AX^B A只能为0或者1 ,剩下的就比较好做的了. #include <iostream> #include<cstdio> #include ...
- ural1057 Amount of degrees 位数统计
#include <iostream> #include <string> using namespace std; ][]; void init(){ f[][] =; ;i ...
- 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 ...
- Ural Amount of Degrees(数位dp)
传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...
- [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 ...
随机推荐
- .NET设计模式(13):享元模式(Flyweight Pattern)(转)
摘要:面向对象的思想很好地解决了抽象性的问题,一般也不会出现性能上的问题.但是在某些情况下,对象的数量可能会太多,从而导致了运行时的代价.那么我们如何去避免大量细粒度的对象,同时又不影响客户程序使用面 ...
- Sqli-labs less 18
Less-18 本关我们这里从源代码直接了解到 对uname和passwd进行了check_input()函数的处理,所以我们在输入uname和passwd上进行注入是不行的,但是在代码中,我们看到了 ...
- Sqli-labs less 38
Less-38 学习了关于stacked injection的相关知识,我们在本关可以得到直接的运用. 在执行select时的sql语句为:SELECT * FROM users WHERE id=' ...
- Sublime Text 编辑器
1.从http://www.sublimetext.com/2 下载Sublime Text 2编辑器. 2.安装Package Control 管理器,用于管理和安装插件包. 下载地址:https: ...
- 在 Java 中如何更高效地存储和管理 SQL 语句?
[编者按]还在为管理 Java 代码中的 SQL 语句而烦恼吗?让 Zemian 帮你摆脱困境吧!本文系 OneAPM 工程师编译整理 注意:使用java.util.Properties#loadFr ...
- POJ 1305 Fermat vs. Pythagoras (毕达哥拉斯三元组)
设不定方程:x^2+y^2=z^2若正整数三元组(x,y,z)满足上述方程,则称为毕达哥拉斯三元组.若gcd(x,y,z)=1,则称为本原的毕达哥拉斯三元组. 定理:正整数x,y,z构成一个本原的毕达 ...
- centOS学习part3:远程工具VNC的安装与配置
0 上一篇(http://www.cnblogs.com/souvenir/p/3875484.html)我们介绍了通过yum安装JDK的实例,初步见识了yum命令的强大.本章我们将继续使用yum命令 ...
- 程序空间(Program memory)
The computer program memory is organized into the following: Data Segment (Data + BSS + Heap) Stack ...
- 简单Ajax例子
一.概述 1.程序执行流程: (1)点击id="testBtn"的按钮,触发validate(); (2)validate()中有调用request.open方法与server交互 ...
- My SQL InnoDB 1217 - Cannot delete or update a parent row:aforeign key constraint fals
InnoDB 允许有外键 MyISAM 不允许有外键 InnoDB修改成MyISAM 证明有外键 一张表如果有其他表的外键关联的是它 它也不能是MyISAM 来自为知笔记(Wiz)