【HDU 3555】 Bomb
2024-08-28 01:08:41
【题目链接】
【算法】
数位DP
【代码】
#include<bits/stdc++.h>
using namespace std;
#define MAXL 15
typedef unsigned long long ULL; ULL T,n,a[MAXL];
ULL dp[MAXL][]; template <typename T> inline void read(T &x) {
ULL f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c -'';
x *= f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
}
inline void getdp() {
ULL i,j,k;
dp[][] = ;
for (i = ; i <= MAXL; i++) {
for (j = ; j <= ; j++) {
for (k = ; k <= ; k++) {
if (j == && k == ) continue;
dp[i][j] += dp[i-][k];
}
}
}
}
inline ULL calc(ULL n) {
ULL i,j,ans = ;
a[] = ;
while (n != ) {
a[++a[]] = n % ;
n /= ;
}
a[a[]+] = ;
for (i = a[]; i >= ; i--) {
for (j = ; j < a[i]; j++) {
if (a[i+] == && j == ) continue;
ans += dp[i][j];
}
if (a[i+] == && a[i] == ) break;
}
return ans;
} int main() { getdp(); read(T);
while (T--) {
read(n);
writeln(n-calc(n+)+);
} return ;
}
最新文章
- Git 简介
- Lua小技巧
- maven - 安装与配置
- Python将文本生成二维码
- 多线程在iOS开发中的应用
- bootstrap 多个 modal 相互遮挡
- 【转】在网页中运行VB6程序
- ";undefined reference to"; 问题解决方法 -链接问题
- C# 中的命名规则
- Spring Uploading Files
- 如何设置lmt的空间警告阀值
- 从Object和Function说说JS的原型链
- 复习上学期的HTML+CSS(1)
- 6.context对象
- anaconda 在内网中代理配置
- mysql常用增删改查命令(纯纪录.orm用得基本功都没了。)
- 转载-YARN的内存和CPU配置
- Qt封装QTcpServer参考资料--QT4中构建多线程的服务器
- 【转】Windows 7 API Internet Connection Sharing(ICS) 与 Wireless Hosted Network构建本地AP
- PAT 1030 Travel Plan[图论][难]