题目链接

我看错题了。。。都是泪啊,不存在3*4^2这种情况。。。系数必须为1。。。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define LL long long
int num[];
LL dp[][];
int k,b;
LL dfs(int pos,int pre,int bound)
{
int i,end;
LL ans = ;
if(pos == -)
return pre == ;
if(pre < )
return ;
if(!bound&&dp[pos][pre] != -)
return dp[pos][pre];
end = bound ? num[pos]:b-;
for(i = ;i <= end;i ++)
{
if(i == )
ans += dfs(pos-,pre,bound&&i == end);
else if(i == )
ans += dfs(pos-,pre-,bound&&i == end);
}
if(!bound)
dp[pos][pre] = ans;
return ans;
}
LL judge(LL x)
{
int pos = ;
while(x)
{
num[pos++] = x%b;
x /= b;
}
return dfs(pos-,k,);
}
int main()
{
LL x,y;
memset(dp,-,sizeof(dp));
cin>>x>>y>>k>>b;
cout<<judge(y)-judge(x-)<<endl;
return ;
}

URAL 1057. Amount of Degrees(数位DP)的更多相关文章

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

  2. Ural 1057 Amount of Degrees

    Description 问[L,R]中有多少能表示k个b次幂之和. Sol 数位DP. 当2进制时. 建出一个二叉树, \(f[i][j]\) 表示长度为 \(i\) 有 \(j\) 个1的个数. 递 ...

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

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

  4. URAL 1057 Amount of Degrees (数位dp)

    Create a code to determine the amount of integers, lying in the set [X;Y] and being a sum of exactly ...

  5. ural 1057 Amount of degrees 【数位dp】

    题意:求(x--y)区间转化为 c 进制 1 的个数为 k 的数的出现次数. 分析:发现其满足区间减法,所以能够求直接求0---x 的转化为 c 进制中 1 的个数为k的数的出现次数. 首先用一个数组 ...

  6. URAL 1057 Amount of Degrees (数位DP,入门)

    题意: 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的,B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足了要求:  17 = 24+2 ...

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

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

  9. ural 1057Amount of Degrees ——数位DP

    link:http://acm.timus.ru/problem.aspx?space=1&num=1057 论文: 浅谈数位类统计问题  刘聪 #include <iostream&g ...

随机推荐

  1. MYSQL建表语法(主键,外键,联合主键)

    在看<Learning SQL>第二版, 慢慢打实SQL的基础. 建表一: ), lname ), gender ENUM(), city ), state ), country ), p ...

  2. wp8 入门到精通 ---转换

             /// <summary>        /// 颜色字符串转Color        /// </summary>        public static ...

  3. 浅学JSON——Json.NET之首次试手

    首次遭遇Json格式,缘由项目中用到Json数据,需要进行解析,为此,将Json数据转为了自己较为熟悉的DataTable格式,以此展示至DataGridView中,验证是否成功. 直接上代码: // ...

  4. VS2012 OpenCV2.4.9 Debug可以允许,Release不可以

    一个简单的程序 #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgu ...

  5. RDS MySQL 全文检索相关问题的处理

    RDS MySQL 全文检索相关问题 1. RDS MySQL 对全文检索的支持 2. RDS MySQL 全文检索相关参数 3. RDS MySQL 全文检索中文支持 3.1 MyISAM 引擎表 ...

  6. SQL.WITH AS.公用表表达式(CTE)(转)

    一.WITH AS的含义    WITH AS短语,也叫做子查询部分(subquery factoring),可以让你做很多事情,定义一个SQL片断,该SQL片断会被整个SQL语句所用到.有的时候,是 ...

  7. DOM--4 响应用户操作和事件(2)

    自定义事件 //旧的方法 //创建 var event = document.createEvent('Event'); //初始化 event.initEvent('build', true, tr ...

  8. BFS(双向) HDOJ 3085 Nightmare Ⅱ

    题目传送门 题意:一个人去救女朋友,两个人都在运动,还有鬼在"扩散",问最少几秒救到女朋友 分析:开两个队列来表示两个人走过的路,一个人走到的地方另一个人已经vis了,那么就是相遇 ...

  9. 转载:robotium typeText与enterText区别

    solo.typeText和solo.enterText方法都可以对EditeText进行测试,达到的测试目的是一样的.存在几点不同: 1.实现上,typeText方法是robotium框架调用系统I ...

  10. git 学习笔记6--remote & log

    git 学习笔记6--remote & log 创建SSH Keys ssh-keygen -t rsa -C "1050244110@qq.com" 本地关联远程 git ...