HDU-4651 Posted on 2019-03-22 | Edited on 2019-05-10 | In hdu | Views: 题意整数拆分,$(1\le n\le 10^5)$ 题解使用五边形定理 其中 ,注意两个条件要分开判断,有大于0的就加上相应的f,不是两个同时成立或者不成立 代码1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950#include <bits/stdc++.h>#define forl(i, l, r) for (int i = l; i <= r; i++)#define forr(i, r, l) for (int i = r; i >= l; i--)#define for1(i, n) for (int i = 1; i <= n; i++)#define for0(i, n) for (int i = 0; i < n; i++)#define meminf(a) memset(a, inf, sizeof(a))#define mem_1(a) memset(a, -1, sizeof(a))#define mem0(a) memset(a, 0, sizeof(a))#define inlld(lld) scanf("%lld",&lld)typedef unsigned long long ull;#define inlf(f) scanf("%lf",&f)#define ind(d) scanf("%d",&d)#define ins(s) scanf("%s",s)#define inf 0x3f3f3f3ftypedef long long ll;#define pi acos(-1.0)#define mod (int)(1e9+7)#define N (int)(1.1e5)using namespace std;int p[N];int main() {#ifndef ONLINE_JUDGE // freopen("/Users/perpeternal/Documents/Sketch/data/in.dat", "r", stdin); // freopen("/Users/perpeternal/Documents/Sketch/data/out.dat","w",stdout);#endif //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); p[0]=1; for1(i,100005){ ll fl=1,an=0,flag=1; while(1){ ll tmp=fl*(3*fl-1)/2; if(i-tmp<0)break; an=(an+flag*p[i-tmp]+mod)%mod; tmp=fl*(3*fl+1)/2; if(i-tmp<0)break; an=(an+flag*p[i-tmp]+mod)%mod; fl++; flag*=-1; } p[i]=an; // printf("%d\n",tmp); } int t,n; ind(t); while(t--){ ind(n); printf("%d\n",p[n]); } return 0;}