博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Poj2229--Sumsets(递推)
阅读量:7281 次
发布时间:2019-06-30

本文共 1233 字,大约阅读时间需要 4 分钟。

Sumsets
Time Limit: 2000MS   Memory Limit: 200000K
Total Submissions: 15052   Accepted: 6001

Description

Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that sum to 7: 
1) 1+1+1+1+1+1+1 
2) 1+1+1+1+1+2 
3) 1+1+1+2+2 
4) 1+1+1+4 
5) 1+2+2+2 
6) 1+2+4 
Help FJ count all possible representations for a given integer N (1 <= N <= 1,000,000). 

Input

A single line with a single integer, N.

Output

The number of ways to represent N as the indicated sum. Due to the potential huge size of this number, print only last 9 digits (in base 10 representation).

Sample Input

7

Sample Output

6

Source

 
题目很有意思, 没想到是个递推, 脑子不够用。
#include 
#include
const int MOD = 1e9;const int N = 1000001;int num[N];void Sieve(){ num[1] = 1; num[2] = 2; num[3] = 2; for(int i = 4; i <= N; i++){ if(i & 1) num[i] = num[i-1]; else num[i] = (num[i-2]%MOD + num[i/2]%MOD)%MOD; }}int main(){ Sieve(); int n; while(scanf("%d", &n) != EOF) printf("%d\n", num[n]); return 0;}

 

转载于:https://www.cnblogs.com/soTired/p/5064645.html

你可能感兴趣的文章
C#中byte类型转换为double类型
查看>>
有意思的网站
查看>>
max3232
查看>>
linux读写ntfs
查看>>
x264 编码器选项分析 (x264 Codec Strong and Weak Points) 1
查看>>
lintcode:带环链表
查看>>
10最好的开放源移动工具的工作场所
查看>>
【转载】为什么不建议<=3G的情况下使用CMS GC
查看>>
CentOS中基于不同版本安装重复包的解决方案
查看>>
vim:查看当前的配置文件名称和地址
查看>>
javaweb学习总结二十二(servlet开发中常见的问题汇总)
查看>>
Nginx 做系统的前端反向proxy
查看>>
Win8 Metro(C#)数字图像处理--2.49Zhang二值图像细化算法
查看>>
嵌入 Office ,doc|docx|xls|xlsx|ppt|pptx|pdf|等
查看>>
Cut Down QtWebkit Library
查看>>
在Windows下Hunchentoot的启动
查看>>
网新恒天2013年校园招聘笔试
查看>>
推荐五星级C语言学习网站
查看>>
windows 下的命令行工具。。
查看>>
使用自定义的BaseAdapter实现LIstView的展示
查看>>