"Dynamic planning" XMU 1028 Game Boy Advance

Source: Internet
Author: User

Topic Links:

http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1028

Main Topic :

The solution of solving the optimal solution of 01 knapsack. Number of objects and object number.

Topic Ideas:

  "Dynamic Planning"

Classic Backpack DP.

Final Inverted solution

1 //2 //by Coolxxx3 //4#include <iostream>5#include <algorithm>6#include <string>7#include <iomanip>8#include <memory.h>9#include <time.h>Ten#include <stdio.h> One#include <stdlib.h> A#include <string.h> - //#include <stdbool.h> -#include <math.h> the #defineMin (a) < (b) ( A):(B)) - #defineMax (a) (a) > (b)? ( A):(B)) - #defineABS (a) ((a) >0? ( A):(-(a))) - #defineLowbit (a) (a& (a)) + #defineSqr (a) ((a) * (a)) - #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b)) + #defineEPS (1E-8) A #defineJ 10000000 at #defineMAX 0x7f7f7f7f - #definePI 3.1415926535897 - #defineN 1004 - #defineM 8204 - using namespacestd; -typedefLong LongLL; in intCas,cass; - intN,m,lll,ans; to intF[n][m]; + intW[n],c[n],q[n]; - intMain () the { * #ifndef Online_judge $ //freopen ("1.txt", "R", stdin);Panax Notoginseng //freopen ("2.txt", "w", stdout); -     #endif the     inti,j; + //for (scanf ("%d", &cas); cas;cas--) A //for (scanf ("%d", &cas), cass=1;cass<=cas;cass++) the //while (~scanf ("%s", s)) +      while(~SCANF ("%d",&N)) -     { $cas=0; $Memset (F,0,sizeof(f)); -scanf"%d",&m); -          for(i=1; i<=n;i++) thescanf"%d",&w[i]); -          for(i=1; i<=n;i++)Wuyiscanf"%d",&c[i]); the          for(i=1; i<=n;i++) -         { Wu              for(j=0; j<w[i];j++) f[i][j]=f[i-1][j]; -              for(j=w[i];j<=m;j++) About             { $F[i][j]=max (f[i-1][j],f[i-1][j-w[i]]+c[i]); -             } -         } -          for(I=n,j=m;i && j>=0; i--) A         { +             if(J<w[i])Continue; the             if(f[i][j]==f[i-1][j-w[i]]+C[i]) -             { $q[++cas]=i; thej-=W[i]; the             } the         } theprintf"%d\n", CAs); -          for(i=cas;i;i--) inprintf"%d", Q[i]); thePuts""); the     } About     return 0; the } the /* the // +  - // the */
don't do it.

"Dynamic planning" XMU 1028 Game Boy Advance

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.