51NOD 1259 整数划分 (五边形定理)
来源:互联网 发布:淘宝剁手说说 编辑:程序博客网 时间:2024/05/29 16:18
题意
将N分为若干个整数的和,求有多少种不同的划分方式。
思路
几个月前妄图用DP过这题失败了= =,今天队友问起这题才想起来我还没过,看到discuss说用五边形定理赶紧去学习了一波。。。
参考ACdreamer巨巨的博客:http://blog.csdn.net/acdreamers/article/details/12259815
代码
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define LL long long#define Lowbit(x) ((x)&(-x))#define lson l, mid, rt << 1#define rson mid + 1, r, rt << 1|1#define MP(a, b) make_pair(a, b)const int INF = 0x3f3f3f3f;const int MOD = 1000000007;const int maxn = 1e5 + 7;const double eps = 1e-8;const double PI = acos(-1.0);typedef pair<int, int> pii;LL ans[maxn];LL temp[maxn];void init(){ int t = 1000; for (int i = -1000; i <= 1000; i++) temp[i+t] = i * (3 * i - 1) / 2; ans[0] = 1; for (int i = 1; i <= maxn; i++) { int sum = 0; for (int j = 1; j <= i; j++) { if (temp[t+j] <= i) { if (j & 1) sum = (sum + ans[i-temp[t+j]] + MOD) % MOD; else sum = (sum - ans[i-temp[t+j]] + MOD) % MOD; } else break; if (temp[t-j] <= i) { if (j & 1) sum = (sum + ans[i-temp[t-j]] + MOD) % MOD; else sum = (sum - ans[i-temp[t-j]] + MOD) % MOD; } else break; } ans[i] = sum; }}int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); init(); int n; while (scanf("%d", &n) != EOF) { printf("%lld\n", ans[n]); } return 0;}
0 0
- 51NOD 1259 整数划分 (五边形定理)
- [五边形数定理 DP] 51Nod 1259 整数划分 V2 & HDU 4651 Partition
- 杭电第五场多校联系-整数划分-五边形定理
- hdu 4658 整数划分+五边形定理 多校第六场
- 整数划分 51Nod
- 51Nod-1259-整数划分 V2
- 51nod 1259 整数划分 V2
- 2013 多校第六场 hdu 4658 Integer Partition(五边形数定理,整数划分)
- HDOJ 4658 Integer Partition(整数划分:母函数+五边形数定理)
- [51nod 1201]整数划分
- 51nod 1201 整数划分
- 51nod-1201 整数划分
- 51Nod-1201-整数划分
- 51nod 1201 整数划分
- 【51Nod 1201】 整数划分
- 【51nod 1201】 整数划分
- 51Nod 1201 整数划分
- 51NOD 1201 整数划分
- 编外话题外
- 乐学成语——显示所有动物类成语的列表
- Major GC和Full GC的区别是什么?触发条件呢?
- 简单易懂的金融"杠杆原理"解说
- 集合
- 51NOD 1259 整数划分 (五边形定理)
- Tomcat如何禁用session(Turn off the Session in Tomcat )
- HDU 1071 The area ----求定积分
- Git SSH Key 生成步骤
- 32. Longest Valid Parentheses
- leetcode 109 Convert Sorted List to Binary Search Tree
- 练字和平时写字完全不一样怎么办?
- 当ListView遇上RecyclerView, ListView将甘拜下风
- 5种CSS_RESET借鉴