UVa 624 CD

Source: Internet
Author: User

UVa 624 CD 01 Backpack Record Path

Descirption: NULL

"Give you a CD of the past to listen to our love at that time."

Simple 01 Backpack + path Recording.

Purple remembrance of the Great God:

can open another array a[i][j], when the dp[i][j] in the dynamic transfer of records, take the item I is a[i][j]=0, otherwise a[i][j]=1; Then the array a[i][j] can be traced back

Gives two ways to print: Recursive and non-recursive

 void  print (int  A,  b) { if  (!a)  if   (Vis[a][b]) {print (a -1 , b- W[a]); printf (  %d   "  else  print (A-1    
 for (int0; I--) {          if(Vis[i][j]) {                  printf ("  ", W[i]); J-= w[i];            }  }

Slag Code:

1#include <iostream>2#include <string.h>3#include <math.h>4#include <algorithm>5#include <stdlib.h>6#include <stdio.h>7 #definell Long Long8 9 using namespacestd;Ten intf[10005], w[ -], N, m; One BOOLvis[ -][10005]; A voidPrintintAintb) { -     if(!a)return;  -     if(Vis[a][b]) { thePrint (A-1, B-W[a]); -printf"%d", W[a]); -     } -     ElsePrint (A-1, b); + } - intMain () + { A      while(~SCANF ("%d%d", &m, &n) && m +N) { atMemset (F,0,sizeof(f)); -memset (Vis,0,sizeof(Vis)); -          for(inti =1; I <= N; i + +){ -scanf"%d", &w[i]); -         } -          for(inti =1; I <= N; i + +){ in              for(intj = m; J >= W[i]; J--){ -                 if(F[j] <= F[j-w[i]] +W[i]) { toF[J] = F[j-w[i]] +W[i]; +VIS[I][J] =1; -                 } the             } *         } $ print (n, m);Panax Notoginseng         //for (int i = n,j = m; i > 0; I-) { -         //if (Vis[i][j]) { the             //printf ("%d", w[i]);  J-= W[i];  +             //  }   A     //    } theprintf"sum:%d\n", F[m]); +     } -     return 0; $}
UVa 624 CD

Nailed IT.

-----------------------

UVa 624 CD

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.