1057

简单的数位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)的更多相关文章

  1. Ural1057. Amount of Degrees 题解 数位DP

    题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...

  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 ...

  3. Ural1057 - Amount of Degrees(数位DP)

    题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...

  4. ural1057 Amount of Degrees

    链接 这题有一点小坑点 就是AX^B  A只能为0或者1  ,剩下的就比较好做的了. #include <iostream> #include<cstdio> #include ...

  5. ural1057 Amount of degrees 位数统计

    #include <iostream> #include <string> using namespace std; ][]; void init(){ f[][] =; ;i ...

  6. 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 ...

  7. Ural Amount of Degrees(数位dp)

    传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...

  8. [TimusOJ1057]Amount of Degrees

    [TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...

  9. 一本通1585【例 1】Amount of Degrees

    1585: [例 1]Amount of Degrees 时间限制: 1000 ms         内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...

随机推荐

  1. C#单链表(数据结构)

    学习单链表的源码项目:http://files.cnblogs.com/xmfdsh/CSharp%E5%8D%95%E9%93%BE%E8%A1%A8.rar 链表是用一组任意的存储单元来存储线性表 ...

  2. 几个Google中国的访问IP

    前面几个IP的访问速度比较快. 74.125.31.106 173.194.45.20 173.194.45.19 173.194.45.18 173.194.45.17 173.194.45.16 ...

  3. Virtualbox网络设置和无UI启动

    因工作需要,在Macbook上安装Ubuntu 14.04.2虚拟机,需要ssh连接操作. 一番查找资料,实践后可以正常工作了,记录一些信息以备用 无UI启动虚拟机,可使用以下命令: VBoxMana ...

  4. 表单中<form>的enctype属性

    application/x-www-form-urlencoded.multipart/form-data.text/plain 上传文件的表单中<form>要加属性enctype=&qu ...

  5. swfObject 使用说明

    1.Embed your SWF with JavaScript 使用方法  swfobject.embedSWF(swfUrl, id, width, height, version, expres ...

  6. Docker初识

    <Docker--从入门到实践>是Docker技术的入门教程,学习时长两天,现整理关键点如下: 1. 什么是Docker? 轻量级操作系统虚拟化解决方案:Go语言实现:下图很好地说明了Do ...

  7. 修改DevExpress中英文提示,将英文改为中文

    1 : 修改DX 提示框中的英文字符 /// <summary> /// 重写DX弹出框 英文变为中文 /// </summary> public class CHS : De ...

  8. Android Drawable体系

  9. JDK环境变量解析

    设置环境变量 在java 中需要设置三个环境变量(1.5之后不用再设置classpath了,但个人强烈建议继续设置以保证向下兼用问题)JDK安装完成之后我们来设置环境变量:右击“我的电脑”,选择“属性 ...

  10. JS中基本类型与包装类型的关系

    对于JS中一些类型的转化的东西,自己测试并得出的结论,有错误的地方请大大们留言. 不多废话,直接贴代码,测试请直接拷贝全部代码: <!DOCTYPE html> <html> ...