Description
将数字N分成至少2份.使用的数字不可重复.
例如5=1+4=2+3,就只有两种拆分的方式.
Format
Input
每一行给出一个数字N
3<=N<=500
整个测试以0代表结束.
Output
输出有多行,每行一个数字,代表拆分的种数
Samples
输入数据 1
3
5
500
0
Copy
输出数据 1
1
2
732986521245023
思路
这道题可以用到背包的思维 ,即1~500塞满一个背包。
代码见下:
#include<bits/stdc++.h>
using namespace std;
long long eee,n,m,jkj,lll=0,a,s2[1000101],n4[10000001],ni[120][101],nj[101],nk[101],b[100001],c[54],d[100001],k,kkk,p,ss[100001][51],sd[100001],sw,t,z0,z1,u0,sc,s0,sm,sx;
bool n8[10001][10001];
struct ll{
int s,e;
}z[10000001];
ll z2[10000001],z3[10000001],zx[10000001];
bool cmp(ll a,ll b){
return a.s<b.s;
}
bool cmp2(ll a,ll b){
return a.e<b.e;
}
bool cmp3(ll a,ll b){
return a.e-a.s<b.e-b.s;
}
int main(){
n=500;
for(int i=1;i<=n;i++) s2[i]=i;
memset(n4,0,sizeof(n4));
n4[0]=1;
for(int i=1;i<=n;i++){
for(int j=n-s2[i];j>=0;j--){
if(n4[j]>=1){
n4[j+i]+=n4[j];
}
}
}
for(int i89=1;;i89++){
cin>>n;
if(n==0) break;
cout<<n4[n]-1<<endl;
}
return 0;
}