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 ...
随机推荐
- 查看windows系统热键占用情况
有时候我们经常用一些软件中的快捷键,但是会发现快捷键设置的很正确,但是就是不起作用.这就是因为这些快捷键被系统或者其他软件占用了. 那么这时我们怎么知道是哪个软件占用了呢?这确实是个纠结的问题,还好大 ...
- Mobile Web 调试指南(2):远程调试
原文:http://blog.jobbole.com/68606/ 原文出处: 阿伦孟的博客(@allenm ) 第一篇中讲解了如何让手机来请求我们开发电脑上的源码,做到了这步后,我们可以改完代码立即 ...
- main函数和启动例程
为什么汇编程序的入口是_start,而C程序的入口是main函数呢?本节就来解释这个问题.在讲例 18.1 “最简单的汇编程序”时,我们的汇编和链接步骤是: $ as hello.s -o hello ...
- uva 11374
Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express, takes resi ...
- POJ 1488
#include <iostream> #include <string> using namespace std; int main() { string s; int i; ...
- LoaderManager使用详解(二)---了解LoaderManager
了解LoaderManager 这篇文章将介绍LoaderManager类,这是该系列的第二篇文章. 一:Loaders之前世界 二:了解LoaderManager 三:实现Loaders 四:实 ...
- C++默认参数(转)
函数的默认参数值,即在定义参数的时候同时给它一个初始值.在调用函数的时候,我们可以省略含有默认值的参数.也就是说,如果用户指定了参数值,则使用用户指定的值,否则使用默认参数的值. void Func( ...
- HDU 1428 漫步校园(记忆化搜索,BFS, DFS)
漫步校园 http://acm.hdu.edu.cn/showproblem.php?pid=1428 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于 ...
- C#中的可空类型
public class Person { public DateTime birth; public DateTime? death; string name; public TimeSpan Ag ...
- ExtJs布局之tabPanel
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...