首页 > 其他分享 >ZOJ 2872 Binary Partitions

ZOJ 2872 Binary Partitions

时间:2022-11-09 20:01:21浏览次数:46  
标签:2872 int ZOJ number test line include into Partitions


Binary Partitions


Time Limit: 2 Seconds       Memory Limit: 65536 KB


Hadi loves binary numbers. So he likes to partition everything into powers of two. He wonders in how many ways he can partition a given number n into powers of two.

For example, there are 2 ways to partition 3: 1+1+1 and 1+2.

Help Him.

Input

The first line of input consists of a single integer T, the number of test-cases. Each test-case consists of a line containing n. (0 <= n <= 2,000,000)

Output

For each test-case, output a line containing number of ways in which n can be partitioned into binary numbers modulo 1,000,000.

Sample Input

4
1
2
3
280

Sample Output

1
2
2

93298


直接当做背包搞好了

#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 2000005;
int n, f[maxn], x;

int main()
{
f[0] = 1;
for (int j = 0; (1 << j) < maxn; j++)
for (int i = (1 << j); i < maxn; i++)
(f[i] += f[i - (1 << j)]) %= 1000000;
while (scanf("%d", &n) != EOF)
{
while (n--)
{
scanf("%d", &x);
printf("%d\n", f[x]);
}
}
return 0;
}



标签:2872,int,ZOJ,number,test,line,include,into,Partitions
From: https://blog.51cto.com/u_15870896/5838705

相关文章

  • ZOJ 2132 the most frequent number
    DescriptionSeven(actuallysix)problemsmaybesomewhatfewforacontest.ButIamreallyunabletodeviseanotherproblemrelatedtoFantasyGameSeries.......
  • ZOJ 3605 Find the Marble
    DescriptionAliceandBobareplayingagame.Thisgameisplayedwithseveralidenticalpotsandonemarble.Whenthegamestarts,Aliceputsthepotsinone......
  • ZOJ 2068 Chopsticks
    DescriptionIt'sDecember2nd,Mr.L'sbirthday!HeinvitedKpeopletojoinhisbirthdayparty,andwouldliketointroducehiswayofusingchopsticks.So,he......
  • ZOJ 3911 Prime Query
    PrimeQueryTimeLimit: 1Second     MemoryLimit: 196608KBYouaregivenasimpletask.Givenasequence A[i] with NHerearetheoperations:Av......
  • ZOJ 3905 Cake
    CakeTimeLimit: 4Seconds     MemoryLimit: 65536KBAliceandBoblikeeatingcakeverymuch.Oneday,AliceandBobwenttoabakeryandboughtm......
  • [bzoj3033] 太鼓达人 (欧拉回路)
    学会了欧拉回路pwpwpwpwpwpDescription七夕祭上,Vani牵着cl的手,在明亮的灯光和欢乐的气氛中愉快地穿行。这时,在前面忽然出现了一台太鼓达人机台,而在机台前坐着的是......
  • BZOJ P3732 Network(Kruskal重构树)
    Network题目描述:给\(N\)个点的无向图\(\left(1\leqN\leq15000\right)\),记为:\(1\dotsN\)图中有\(M\)条边\(\left(1\leqM\leq30000\right)\),第\(i\)......
  • Select type&partitions (2)—mysql执行计划(四十八)
    前面说了explain的table是表名,显示在前面的代表驱动表,正常select会出现不同的id,但如果子查询本来是两个select,但被优化成连接查询,就会导致是相同的id,union查询会出现临时表,i......
  • 树上连通有关背包:【BZOJ4182】shopping &【HDU6566】The Hanged Man
    选这两道题是因为这两道题都是树上背包,而且选的点的要求都与连通性有关,而且都是按dfs序DP来模拟不断加入物品,而且都能用树剖和点分治优化(不过优化的点一个跟子树大小有......
  • 【XSY2444】【BZOJ4042】【CERC2014】【luogu4757】Parades(树形dp+状压dp)
    题面Description从前有个A国,它有\(n\)个城市和\(n-1\)条道路。每条路连接两个城市。城市之间两两可达。每个城市与不超过10条道路相连。现在给出\(m\)条路径,要求从这些......