ural 1057Amount of Degrees ——数位DP
link:http://acm.timus.ru/problem.aspx?space=1&num=1057
论文: 浅谈数位类统计问题 刘聪
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
][];
int bto2(int x, int b)
{
], cnt = , ans = ;
while (x)
{
tm[cnt++] = x % b; x /= b;
}
; i >= ; --i)
{
))
{
ans += ((<<(i+))-); break;
}
<<i);
}
return ans;
}
int calc(int x, int k)
{
, ans = ;
; i > ; --i)
{
<<i))
{
++tot; if (tot > k) break;
x = x ^ (<<i);
}
<<(i - )) <= x) ans += (a[i-][k-tot]);
}
if (tot + x == k) ++ans;
return ans;
}
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin );
#endif // ONLINE_JUDGE
int x,y,k,b;
memset(a, , sizeof(a));
a[][] = ;
; i <= ; ++i)
{
a[i][] = a[i-][];
; j <= i; ++j) a[i][j] = a[i-][j] + a[i-][j-];
}
while (~scanf("%d%d%d%d",&x, &y, &k, &b))
{
;
)
{
ans = calc(y, k) - calc(x - , k);
}
else
{
, b), Y = bto2(y, b);
ans = calc(Y, k) - calc(X, k);
}
printf("%lld\n", ans);
}
;
}
走吧,小胖!
ural 1057Amount of Degrees ——数位DP的更多相关文章
- Ural1057 - Amount of Degrees(数位DP)
题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...
- URAL 1057. Amount of Degrees(数位DP)
题目链接 我看错题了...都是泪啊,不存在3*4^2这种情况...系数必须为1... #include <cstdio> #include <cstring> #include ...
- [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 ...
- 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 1057(数位dp)
数位dp题,关键是用树的思维去考虑. 对于一个数字X,要是能表示成K个B的不同次幂,等价于X在B进制下有且只有K个位上面的数字为一,其他位上的数字都为0. 具体读者可以去参考,国家集训队李聪的论文,里 ...
- 2018.09.07 Amount of degrees(数位dp)
描述 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和. 例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 17 = 24+20, ...
- URAL 1057 数位dp
题目传送门http://acm.timus.ru/problem.aspx?space=1&num=1057 最近在学习数位dp,具体姿势可以参照这篇论文:http://wenku.baidu ...
- 【数位DP】[LOJ10163]Amount of Degrees
发现自己以前对数位DP其实一窍不通... 这题可以做一个很简单的转换:一个数如果在$b$进制下是一个01串,且1的个数恰好有k个,那么这个数就是合法的(刚开始没判断必定是01串,只判断了1的个数竟然有 ...
随机推荐
- MySQL数据库一个字段对应多个值得模糊查询
当一个字段想模糊查询出多个字段的时候,正常情况下一般会这么作 select * from a where name like 'a%' or name like 'b%' ....or ...; 但是 ...
- 《BI那点儿事》数据流转换——数据转换
数据转换执行类似于T-SQL中的函数CONVERT或CAST的功能.数据转换的编辑界面如图,选择需要转换的列,在DataType下拉列表中选择需要的数据类型.Output Alias栏内设置输出时使用 ...
- 左边图标右边文字,在div里居中
- Delphi 使用之连接数据库
DELPHI 中的数据库开发有很多种类的,可以连接Access数据库.MS SQL Server 数据库.Oracle 数据库.MySQL数据库等等,一般连接有两种方式:BDE和ADO两种方式, 都是 ...
- SUBLIME TEXT 2 设置文件详解
SUBLIME TEXT 2 设置文件详解 Preferences.sublime-settings文件: // While you can edit this file, it’s best to ...
- 在不格式化原有系统盘的情况下,利用grub4dos+firadisk制作RamOS VHD Win7总结
在不格式化原有系统盘的情况下,利用grub4dos+firadisk制作RamOS VHD Win7总结在不格式化原有系统盘的情况下,用grub4dos+firadisk安装WIN7到VHD,内存大的 ...
- SQL语句中SUM与COUNT的区别
SUM是对符合条件的记录的数值列求和 COUNT 是对查询中符合条件的结果(或记录)的个数 例如: 表fruit id name price 1 apple 3.00 2 ...
- mysql查询结果导出到文件
方法一: 直接执行命令: mysql> select count(1) from table into outfile '/tmp/test.xls'; Query OK, 31 rows ...
- spring随手笔记3:销毁方法
1. public class HelloWorld { private String msg; public void setMsg(String msg) { this.msg = msg; } ...
- JS如何判断包括IE11在内的IE浏览器 <转载>
今天碰到一个奇怪的问题,有一个页面,想指定用IE浏览器打开,在VS开发环境没有问题,但部署到服务器上,即使是用IE打开页面,还是提示“仅支持IE”,真是晕啊!! 判断是否IE浏览器用的是window. ...