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