Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int t,n;
- int nums[12];
- int used[12];
- int calc(int total,int first){
- int i,j;
- int done=0;
- for(i=first; i<n; i++) {
- if (used[i]) {
- continue;
- }
- if (total == nums[i]) {
- for(j=0; j<i; j++) {
- if (used[j]) {
- printf("%d+", nums[j]);
- }
- }
- printf("%d\n", nums[i]);
- while(i<n && nums[i+1]==nums[i]) {
- i++;
- }
- done=1;
- } else if (total > nums[i]) {
- used[i]=1;
- done += calc(total-nums[i], i+1);
- used[i]=0;
- while(i<n && nums[i+1]==nums[i]) {
- i++;
- }
- }
- }
- return done;
- }
- int main() {
- int i;
- while(1) {
- scanf("%d %d", &t, &n);/*Leo t y numero del arreglo*/
- for(i=0; i<n; i++) {
- scanf("%d", &nums[i]);
- used[i]=0;
- }
- if (n==0) {
- break;
- }
- printf("Sums of %d:\n", t);
- if (!calc(t, 0)) {
- printf("NONE\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement