POJ-2229
Sumsets
Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 19599 Accepted: 7651 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+4Help 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
7Sample Output
6
题意:
给出一个整数n,求n有多少种由2的幂次之和组成的方案.
当n为奇数的时候,那么所求的和式中必有1,则dp[n]==dp[n-1];
当n为偶数的时候,可以分两种情况:
1.含有1,个数==dp[n-1];
2.不含有1,这时每个分解因子都是偶数,将所有分解因子都除以二,所得的结果刚好是n/2的分解结果,并且一一对应,则个数为dp[n/2];
AC代码:
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
using namespace std; const long long MOD=; int dp[]; int main(){
ios::sync_with_stdio(false);
int n;
while(cin>>n&&n){
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<=n;i++){
if(i&){
dp[i]=dp[i-];
}
else{
dp[i]=(dp[i-]+dp[i>>])%MOD;
}
}
cout<<dp[n]<<endl;
}
return ;
}
POJ-2229的更多相关文章
- poj 2229 【完全背包dp】【递推dp】
poj 2229 Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 21281 Accepted: 828 ...
- poj -2229 Sumsets (dp)
http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...
- poj 2229 一道动态规划思维题
http://poj.org/problem?id=2229 先把题目连接发上.题目的意思就是: 把n拆分为2的幂相加的形式,问有多少种拆分方法. 看了大佬的完全背包代码很久都没懂,就照着网上的写了动 ...
- poj 2229 Ultra-QuickSort(树状数组求逆序数)
题目链接:http://poj.org/problem?id=2299 题目大意:给定n个数,要求这些数构成的逆序对的个数. 可以采用归并排序,也可以使用树状数组 可以把数一个个插入到树状数组中, 每 ...
- POJ 2229 Sumsets
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 11892 Accepted: 4782 Descrip ...
- DP:Sumsets(POJ 2229)
数的集合问题 题目大意:给定你一个整数m,你只能用2的k次幂来组合这个数,问你有多少种组合方式? 这一题一看,天啦太简单了,完全背包?是不是? 不过的确这一题可以用完全背包来想,但是交题绝对是TLE ...
- poj 2229 Sumsets DP
题意:给定一个整数N (1<= N <= 1000000),求出以 N为和 的式子有多少个,式子中的加数只能有2的幂次方组成 如5 : 1+1+1+1+1.1+1+1+2.1+2+2.1+ ...
- poj 2229 Sumsets(dp 或 数学)
Description Farmer John commanded his cows to search . Here are the possible sets of numbers that su ...
- Sumsets(POJ 2229 DP)
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 15293 Accepted: 6073 Descrip ...
- poj 2229 DP
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 15326 Accepted: 6088 Descrip ...
随机推荐
- WPF学习之深入浅出话模板
图形用户界面应用程序较之控制台界面应用程序最大的好处就是界面友好.数据显示直观.CUI程序中数据只能以文本的形式线性显示,GUI程序则允许数据以文本.列表.图形等多种形式立体显示. 用户体验在GUI程 ...
- Using ADO.NET Data Service
ADO.NET Data Service是随同Visual Studio 2008 SP1提供的用于构建在数据对象模型 (如EF-DEMX, LINQ-DBML) 之时来快速提供企业网内外的轻量级数据 ...
- Awesome Vue.js vue.js学习资源链接大全 中文
https://blog.csdn.net/caijunfen/article/details/78216868
- android菜鸟学习笔记8----Activity(一)
Activity是android应用程序中重要的组件之一,常听到的android四大组件是Activity.Service.BroadcastReceiver和ContentProvider.它间接继 ...
- 动态库对外暴露api的方法
1 windows的动态库 在要export的函数声明的前面加上__declspec(dllexport)标识这个函数是从该dll中export出来给其它模块使用的. declspec是declare ...
- 更新pip10后 ImportError: cannot import name ‘main'(转)
解决:找到报错文件,也就是那个pip,然后cd进目录 vi 编辑pip,将里面的内容改为如下所示: # -*- coding: utf-8 -*- import re import sys from ...
- 一文看透 Redis 分布式锁进化史(解读 + 缺陷分析)(转)
近两年来微服务变得越来越热门,越来越多的应用部署在分布式环境中,在分布式环境中,数据一致性是一直以来需要关注并且去解决的问题,分布式锁也就成为了一种广泛使用的技术,常用的分布式实现方式为Redis,Z ...
- ubuntun下安装sublime text
Sublime Text 3 是一款轻量级.跨平台的文本编辑器.可安装在ubuntu,Windows和MAC OS X上高级文本编辑软件,有一个专有的许可证,但该程序也可以免费使用,无需做逆向工程.如 ...
- 微信小程序配置详解
在之前已经通过微信公众平台的官方网站https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/devtools.html,注册好小程序并且登录成功后(这里主 ...
- -es6的部分语法
es6的语法 一 . let 和 var 的区别 : 1 . let 和 val 的区别 : ES6新增了let命令 , 用来声明变量,它的用法类似于 var (ES5), 但是所声明的变量,只在l ...