Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
可能有重复数字,可以这样“打表”#include <cstdio> #include <cstring> using namespace std; int n,cnt=0,a[20]={1},c[105][20],vis[105],ans; void dfs(int t,int now) { if(now>n||t>=ans) return; if(now==n) { if(t<ans) { ans=t; c[n][0]=t; for (int i=1;i<=t;i++) c[n][i]=a[i-1]; } return; } memset(vis,0,sizeof(vis)); for (int i=t-1;i>=0;i--) for (int j=i;j>=0;j--) { a[t]=a[i]+a[j]; if(a[t]<a[t-1])break; if(vis[a[t]]==0) { vis[a[t]]=1; dfs(t+1,a[t]); } } } int main() { while(++n<=100) { ans=0x3f3f3f3f; dfs(1,1); } while(scanf("%d",&n)&&n) { for (int i=1;i<c[n][0];i++) printf("%d ",c[n][i]); printf("%d\n",c[n][c[n][0]]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator