【题目链接】

点击打开链接

【算法】

数位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 ;
}

最新文章

  1. Git 简介
  2. Lua小技巧
  3. maven - 安装与配置
  4. Python将文本生成二维码
  5. 多线程在iOS开发中的应用
  6. bootstrap 多个 modal 相互遮挡
  7. 【转】在网页中运行VB6程序
  8. &quot;undefined reference to&quot; 问题解决方法 -链接问题
  9. C# 中的命名规则
  10. Spring Uploading Files
  11. 如何设置lmt的空间警告阀值
  12. 从Object和Function说说JS的原型链
  13. 复习上学期的HTML+CSS(1)
  14. 6.context对象
  15. anaconda 在内网中代理配置
  16. mysql常用增删改查命令(纯纪录.orm用得基本功都没了。)
  17. 转载-YARN的内存和CPU配置
  18. Qt封装QTcpServer参考资料--QT4中构建多线程的服务器
  19. 【转】Windows 7 API Internet Connection Sharing(ICS) 与 Wireless Hosted Network构建本地AP
  20. PAT 1030 Travel Plan[图论][难]

热门文章

  1. 牛客练习赛1 矩阵 字符串二维hash+二分
  2. 发布npm包
  3. 洛谷——P3576 [POI2014]MRO-Ant colony
  4. P2136 拉近距离(spfa判负环)
  5. 关于SIP一些总结
  6. 【Java TCP/IP Socket】Java NIO Socket VS 标准IO Socket
  7. 虽然今天angular5发布了,但我还是吧这篇angularjs(1)+webpack的文章发出来吧哈哈哈
  8. 50 个 Bootstrap 插件
  9. firefox os 开发模拟器1.4版本号安装开发具体解释
  10. SolidEdge 如何绘制辅助视图