UVA 4857 Halloween Costumes Group Backpack

Source: Internet
Author: User

Title Link: Https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem &problem=2858

Test instructions: give you the style of the clothes you need to wear for n days, each time you can wear clothes, take off the clothes can not be used (may again wear), ask at least how many clothes to attend all the banquets

Group Backpack Template Questions:

DP[I][J]; If the first J is worn, dp[i][j]=d[i][j-1]+1;

If you do not wear, you can think of, I to the j-1 range must have this dress,dp[i][j]=dp[i][k-1]+dp[k][j-1],i<=k<=j-1;a[j]==a[k];

Code:

#include <iostream> #include <cstring> #include <cmath>using namespace Std;const int Maxn=110;int a[    Maxn];int Dp[maxn][maxn];int Main () {int t,i,j,k;        while (cin>>t) {int p=1;            while (t--) {int n,m;            cin>>n>>m;            int i,j;            for (i=1;i<=n;i++) {cin>>a[i];            } memset (Dp,0,sizeof (DP));                for (i=1;i<=n;i++) dp[i][i]=1;                cout<< "haha" <<endl;                        for (i=n-1;i>=1;i--) {for (j=i+1;j<=n;j++) {                        dp[i][j]=dp[i][j-1]+1; for (k=i;k<=j-1;k++) {if (A[j]==a[k]) dp[i]                        [J]=min (Dp[i][j],dp[i][k-1]+dp[k][j-1]); }}} cout<< "Case" <<p++<< ":" <<dp[1][n]<<endl; }} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVA 4857 Halloween Costumes Group Backpack

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.