DP_Sumsets
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
题意:整数N用2^n之和的形式表示的方案数
思路:当N>1时,若N为奇数,则每个分解方案中至少含有一个1项。此时若每种分解方案中去掉一个1项,方案数不发生改变。
即 N分解的方案数=(N-1)分解的方案数
若该N为偶数,则分为两类情况:
1、含有1项,同上,每个方案中去掉1项,方案数不变。
2、不含有1项,此时每个方案中最小项应为2,若将每一项除2,方案数不变。
即 N分解的方案数=(N-1)分解的方案数+(N/2)分解的方案数。
边界条件:当N=1时只有一种分解方案。
注意:可能溢出,需要取模
#include<cstdio>
int s[];
int main()
{
int n; s[]=;
for( int i=; i<=; i++){
if( i%== )
s[i]=(s[i-]+s[i/])%;
else
s[i]=s[i-];
}
while(~scanf("%d",&n)){
printf("%d\n",s[n]);
} return ;
}
DP_Sumsets的更多相关文章
随机推荐
- 1-7HSB色彩模式
http://www.missyuan.com/thread-350721-1-1.html HSB色彩模式色相hue.饱和度saturation.明度brightness 在HSB模式中,S和B的取 ...
- 应用fluent二维单向流泥沙冲刷作用下河床变形代码【转载】
本代码转载自:http://www.codeforge.cn/read/260028/keti_2d_b.c__html #include "udf.h" #define Rho ...
- 创建createElement
let oDiv = { tag:'div', props:{ id:'box' } }: let oP = createElement('p',{'class':'list'},['周一']) ...
- netframework webapi IogAttribute记录request参数和错误信息
参考博客 https://www.cnblogs.com/hnsongbiao/p/7039666.html 书写LogFilterAttribute public class LogFilterAt ...
- Resend a Request by fiddler
Resend a Request You can resend a request directly from the Sessions List, or save requests to resen ...
- php学习之单例模式
<?php class Dog { private function __construct() { } //静态属性保存单例对象 static private $instance; stati ...
- Coarse-to-Fine超分辨率相关
1.A Coarse-to-Fine Subpixel Registration Method to Recover Local Perspective Deformation in the Appl ...
- Android 自定义AlertDialog退出对话框
Android 自定义AlertDialog退出对话框 转 https://blog.csdn.net/wkh11/article/details/53081634在项目中很多时候会出现点击返回键出现 ...
- Oracle11g安装与卸载教程
1.1,前言: 电脑太卡,鄙人穷屌丝啊,没钱买新电脑,想想周六日还要耍游戏就给电脑重做了个系统,糟糕的是电脑上的各种环境,工具都需要重新装一边,包括oracle数据库- -,依稀记得昨天装了一上午的数 ...
- 一百三十一:CMS系统之轮播图上传图片功能
将七牛js放到common下 把获取uptoken的接口放到common视图中 把初始化七牛放到banners.js中 //初始化七牛$(function () { qiniujs.setUp({ ' ...