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的更多相关文章
随机推荐
- .netcore signalR 实时消息推送
服务器端引入包 Install-Package Microsoft.AspNetCore.SignalR客户端引入包 npm install @aspnet/signalr <template ...
- codeforces533E
Correcting Mistakes CodeForces - 533E Analyzing the mistakes people make while typing search queries ...
- iTerm2 + oh my zsh +agnoster
安装iTerm2 iTerm2官方下载地址 http://www.iterm2.com/downloads.html 安装Oh My Bash 1.通过cat /etc/shells命令可以查看当前系 ...
- 中国萌兔-月饼工厂流水线 -万圣节萌宠-月饼售罄后续-B站东予薏米
B站(Blibli)up主,东予薏米.下面画的五只兔兔,两只狗狗,一只猫猫都是她家的 啊!有个会画画的主人真是幸福- 蹦迪的那个兔兔头昏脑胀,敷了冰袋和膏药哈哈哈哈,好可爱! 下班了下班了~今天真是太 ...
- protected-broadcast 规范使用系统应用组件自定义广播
1. protected-broadcast 规范使用系统应用组件自定义广播 参考:https://blog.csdn.net/TaylorPotter/article/details/7019424 ...
- ubuntu 安装百度云客户端
下载地址:http://pan.baidu.com/download 如果没有安装alien,安装 luo@luo-ThinkPad-W540:~$sudo apt-get install alien ...
- train_faster_rcnn.sh
#!/bin/bash set -x set -e export PYTHONUNBUFFERED="True" GPU_ID=$1 DATASET=$2 NET=$3 array ...
- linux简单命令3---帮助命令
1:帮助命令:man 命令: 2:这个帮助用的比较多(还是中文):命令 --help 3:shell帮助 4:详细命令(比man更详细)帮助,用的少,比较麻烦:info
- java+上传大文件
在Web应用系统开发中,文件上传和下载功能是非常常用的功能,今天来讲一下JavaWeb中的文件上传和下载功能的实现. 先说下要求: PC端全平台支持,要求支持Windows,Mac,Linux 支持所 ...
- 升级chrome浏览器导致网站登录功能不能用
笔者开发一个java web项目,低版本的chrome(74以下)可以正常登录,升级到chrome74不能正常登录,登录成功后url会携带一个jsessionid=xxxxxx. 登录成功那个页面有s ...