题意:给定一个n。求区间[1, n]之间的全部的a的个数。a满足:

a能整除  把a表示自身二进制以后1的个数

思路:题意非常绕....

数位dp,对于全部可能的1的个数我们都dfs一次

对于某一个可能的1的个数p来说。状态dp(len, i, j, k)里的每一位分别表示当前位,当前确定位的值模除p,已经有了多少个1。是否已经小于给定的n。

注意的是这题范围非常大,要用unsigned long long 来定义n

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<ctime>
#define eps 1e-6
#define ULL unsigned long long
#define LL long long
#define pii (pair<int, int>)
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int digit[100];
ULL cnt_one;
ULL n;
LL d[100][100][100];
LL dfs(int len, ULL r, int k, int s) {
if(!len) return (r==0&&k==cnt_one) ? 1:0;
if(!s && d[len][r][k]!=-1) return d[len][r][k];
LL ans = 0;
ans += dfs(len-1, r, k, s&&!digit[len]);
if(!(s&&!digit[len]) && k<cnt_one) ans += dfs(len-1, (r+(1ULL<<(len-1)))%cnt_one, k+1, s&&digit[len]);
if(!s) d[len][r][k] = ans;
return ans;
}
ULL solve(ULL n) {
int cnt = 0, su = 0;
while(n) {
digit[++cnt] = n & 1;
su++; n >>= 1;
}
LL ans = 0;
for(cnt_one = 1; cnt_one <= su; cnt_one++) {
memset(d, -1, sizeof(d));
ans += dfs(cnt, 0, 0, 1);
}
return ans;
}
int main() {
while(cin >> n) {
cout << solve(n) << endl;
}
return 0;
}

最新文章

  1. 《HiWind企业快速开发框架实战》(1)框架的工作原理
  2. oracle行转列与列转行
  3. 十分钟了解分布式计算:Google Dataflow
  4. KinectV2+Ubuntu 14.04+Ros 安装教程
  5. 微信内置浏览器的JS API
  6. 绘制圆动画--重写view
  7. Android 中PopupWindow使用 (转)
  8. Jquery 基本知识(二)
  9. gtest
  10. Greedy:Saruman&#39;s Army(POJ 3069)
  11. vs c++中读取数据流并存储
  12. mvc3.0中[ValidateInput(false)]失效的问题
  13. 通过GitHub Pages建立个人站点(详细步骤)
  14. CSS基础知识之position
  15. 《天书夜读:从汇编语言到windows内核编程》三 练习反汇编C语言程序
  16. 李耀于NOIP2010集训出的题 Dvalue
  17. About Windows 10 April 2018 Update
  18. UOJ#7. 【NOI2014】购票 点分治 斜率优化 凸包 二分
  19. Java-Servlet--《12-WEB应用中的普通Java程序如何读取资源文件.mp4》 有疑问
  20. 位运算------按位与、按位或、按位异或、取反、&lt;&lt;、&gt;&gt;、&gt;&gt;&gt;

热门文章

  1. python spark 通过key来统计不同values个数
  2. CodeForces 596A
  3. 转四种常见的post请求
  4. mysql 从库落后主库太多优化
  5. Linux Shell Scripting Cookbook 读书笔记 6
  6. springboot的推荐模板引擎-Thymeleaf
  7. SQL Server阻塞诊断
  8. 使用Micrisoft.net设计方案 第一章 企业解决方案中构建设计模式
  9. hdu2282 Chocolate 完美匹配 + 拆点
  10. 构造定律(constructal law)-构造定律作为第二个时间箭头,将和热力学第二定律一道将宇宙推向无序。