Sumsets(POJ 2229 DP)
Time Limit: 2000MS | Memory Limit: 200000K | |
Total Submissions: 15293 | Accepted: 6073 |
Description
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
Output
Sample Input
7
Sample Output
6 分两种情况讨论:
当n为奇数时,划分中肯定存在1,那么dp[i]=dp[i-1];
当n为偶数时,可以把划分情况分为含有1和没有1两种情况
含有1,那么i-1为奇数,dp[i-1];
不含有1,那么划分中都是偶数,相当于dp[i>>1]的每种划分的两倍;
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int M=;
unsigned long long dp[];
int main()
{
unsigned long long n,i,j;
scanf("%lld",&n);
dp[]=;
for(i=;i<=n;i++)
dp[i] = (i% ?dp[i-]:(dp[i-]+dp[i>>]))%M;
printf("%lld\n",dp[n]);
return ;
}
Sumsets(POJ 2229 DP)的更多相关文章
- Palindrome(POJ 1159 DP)
Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 58168 Accepted: 20180 De ...
- poj 3311(状态压缩DP)
poj 3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...
- poj 1185(状态压缩DP)
poj 1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
- 【POJ 3140】 Contestants Division(树型dp)
id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS Memory Limit: 65536K Tot ...
- 【POJ 2486】 Apple Tree(树型dp)
[POJ 2486] Apple Tree(树型dp) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8981 Acce ...
- HDU 3016 Man Down (线段树+dp)
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- dp乱写1:状态压缩dp(状压dp)炮兵阵地
https://www.luogu.org/problem/show?pid=2704 题意: 炮兵在地图上的摆放位子只能在平地('P') 炮兵可以攻击上下左右各两格的格子: 而高原('H')上炮兵能 ...
- HDU 2457 DNA repair(AC自动机+DP)题解
题意:给你几个模式串,问你主串最少改几个字符能够使主串不包含模式串 思路:从昨天中午开始研究,研究到现在终于看懂了.既然是多模匹配,我们是要用到AC自动机的.我们把主串放到AC自动机上跑,并保证不出现 ...
随机推荐
- 纯js实现div内图片自适应大小
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 异步编程设计模式 - IronPythonDebugger
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsof ...
- c# 弹出框-后台调前台函数
前台代码: <script src="../../../Common/Scripts/Order/popup.js" type="text/javascript&q ...
- This application failed to start because it could not find or load the Qt platform plugin "windows"
发生以上错误的Qt版本应该是Qt 5.0.0以上的版本吧. 出现标题错误的大致原因是:因为Qt是跨平台的库,需要依赖于相关的平台库.有个Platform的文件夹,里面有相关dll文件. referen ...
- Android_Studio 及SDK下载
Android Studio includes all the tools you need to build apps for Android. DOWNLOAD ANDROID STUDIO 2. ...
- javascrpit开发连连看记录-小游戏
工作之余,总想做点什么有意思的东西.但是苦于不知道做什么,也就一直没有什么动作.在一个午饭后,跟@jedmeng和@墨尘聊天过程中,发现可以写一些小东西来练练手,有以下几点好处: 1. ...
- RAID,mdadm(笔记)
RAID: 级别:仅代表磁盘组织方式不同,没有上下之分:0: 条带 性能提升: 读,写 冗余能力(容错能力): 无 空间利用率:nS 至少2块盘1: 镜像 性能表现:写性 ...
- hdu 4400 Mines(离散化+bfs+枚举)
Problem Description Terrorists put some mines in a crowded square recently. The police evacuate all ...
- XCode中在提示窗体中对已弃用的API接口画上红线
当我们在XCode中写程序时会不断的出现相关API提示窗体,那敲起来是一个爽啊. 有时候会看到一些API已经弃用了被画上红色的横线.说明该接口已经被弃用,仍保留,但不建议使用,对弃用API实现画横线事 ...
- [Cycle.js] Hello World in Cycle.js
Now you should have a good idea what Cycle.run does, and what the DOM Driver is. In this lesson, we ...