标签:rip ref log use lib inline with can reg
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 5273 | Accepted: 2833 | Special Judge |
Description
Input
Output
Sample Input
5 7 12 15 77 0
Sample Output
1 2 4 5 1 2 4 6 7 1 2 4 8 12 1 2 4 5 10 15 1 2 4 8 9 17 34 68 77
Source
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <cstring> 5 #define min(a, b) ((a) < (b) ? (a) : (b)) 6 #define max(a, b) ((a) > (b) ? (a) : (b)) 7 8 inline void read(int &x) 9 { 10 x = 0;char ch = getchar(), c = ch; 11 while(ch < ‘0‘|| ch > ‘9‘)c = ch, ch = getchar(); 12 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar(); 13 if(c == ‘-‘)x = -x; 14 } 15 16 const int MAXN = 100 + 10; 17 18 int num[MAXN], n, b[MAXN], ID; 19 20 int dfs(int step) 21 { 22 if(num[step - 1] == n) return 1; 23 if(step > ID)return 0; 24 register int tmp; 25 for(register int i = step - 1;i >= 1;-- i) 26 for(register int j = i;j >= 1;-- j) 27 { 28 tmp = num[i] + num[j]; 29 if(tmp <= num[step - 1] || b[tmp] || tmp > n)continue; 30 num[step] = tmp; 31 b[tmp] = 1; 32 if(dfs(step + 1)) return 1; 33 b[tmp] = 0; 34 } 35 return 0; 36 } 37 38 int main() 39 { 40 num[1] = 1; 41 while(scanf("%d", &n) != EOF && n) 42 { 43 for(register int i = 1;i <= n;++ i) 44 { 45 ID = i; 46 memset(b, 0, sizeof(b)); 47 if(dfs(2)) 48 { 49 for(register int j = 1;j <= i;++ j) 50 printf("%d ", num[j]); 51 putchar(‘\n‘); 52 break; 53 } 54 } 55 } 56 return 0; 57 }
标签:rip ref log use lib inline with can reg
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7422437.html