zoj 2872 Binary Partitions(简单递推)
来源:互联网 发布:怎么在淘宝里买东西啊 编辑:程序博客网 时间:2024/05/10 03:50
【题目大意】:把一个数拆成若干个2的幂的和,问有几种拆法。
【解题思路】:递推,当一个数是奇数的时候,没办法,它只能从它前面的那个偶数加个1转移过来。当一个数是偶数的话,可以由它前一个数+1转移过来,也可以是它的一半转移过来,因为偶数换成二进制之后末尾一定是0,也就是偶数左移一位的组合方式。
【代码】:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>#include <cmath>#include <string>#include <cctype>#include <map>#include <iomanip> using namespace std; #define eps 1e-8#define pi acos(-1.0)#define inf 1<<30#define linf 1LL<<60#define pb push_back#define lc(x) (x << 1)#define rc(x) (x << 1 | 1)#define lowbit(x) (x & (-x))#define ll long long#define mod 1000000int f[2001000];void init(){ memset(f,0,sizeof(f)); f[0]=1; f[1]=1; for (int i=2; i<=2000100; i++){ if (i%2==0) f[i]=(f[i-1]+f[i/2])%mod; else f[i]=f[i-1]%mod; }}int main() { init(); int T,n; cin >> T; while (T--){ scanf("%d",&n); cout << f[n] << endl; } return 0;}
f[n][k]:至少以2^k的分量去分解n时有多少种分解方案。题目的解即为f[n][0]。
- zoj 2872 Binary Partitions(简单递推)
- ZOJ 2872 Binary Partitions
- 简单dp之递推(2)--ZOJ 3747
- zoj 3538 递推
- zoj 1383 Binary Numbers&&zoj 1491 Climbing Worm(简单)
- Partitions
- UVA10943简单递推
- hdu2501 简单递推
- 简单递推
- 简单递推
- 简单递推
- 简单递推
- 简单递推
- ZOJ 3182 Nine Interlinks(递推)
- ZOJ Problem Arrangement 递推+状压
- HDOJ-3788 ZOJ问题(递推)
- [递推+dfs]ZOJ 3436. July Number
- hdoj 3788 zoj问题(递推)
- 如何让你的网站快照每天都更新
- MySQL数据导出导入
- iframe异步加载技术及性能
- java实现动态切换上网IP (ADSL拨号上网) java 断网重连 (原)读取cmd消息 乱码解决
- 单例模式 将的很细
- zoj 2872 Binary Partitions(简单递推)
- 如何设置从第三页插入页码
- 用WPF和D3D开发游戏编辑器简介(3)
- Dll分配的内存块,应用释放的问题
- 第一次写汇编的成果及感受
- Windows下动态内存分配方式
- 一段将网页静态化的JAVA代码
- kruskal_poj 2485 Highways
- C++新手关于标准库学习笔记