POJ 1252 Euro Efficiency

Source: Internet
Author: User
Tags cmath

Backpack or BFS


Italy is said to give you a few basic currencies, composed of 1~100 all currencies, using essentially the amount of money with the smallest.

Export usage probability. And the maximum amount of use.


It is possible to BFS.

Just remember to keep the array open. There may be 100 = 99+99-98 conditions.


A backpack is a complete backpack, the least likely to be added by how much.

Then make a 01 backpack to see if it can be reduced.


Backpack:

#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># Include<cmath> #define INF 0x7fffffff#define EPS 1e-6#define LL long longusing namespace Std;int dp[10002];int value    [7];int Main () {int t;    scanf ("%d", &t);        while (t--) {int m=10001;        for (int i=0; i<6; i++) scanf ("%d", &value[i]);        for (int i=1; i<m; i++) dp[i]=10001;        dp[0]=0; for (int i=0, i<6; i++) {for (int j=value[i]; j+value[i]<m; J + +) {dp[j]=            Min (dp[j-value[i]]+1,dp[j]);//printf ("%d:%d==\n", j,dp[j]);                }} for (int i=0, i<6; i++) {for (int j=m-value[i]; j>0; j--) {      Dp[j]=min (Dp[j+value[i]]+1,dp[j]);//printf ("%d:%d==\n", j,dp[j]);      }} double ans=0;        int maxn=0;            for (int i=1; i<=100; i++) {//printf ("%d:%d\n", I,dp[i]);            Ans+=dp[i];        Maxn=max (Maxn,dp[i]);    } printf ("%.2f%d\n", ANS/100.0,MAXN); }}



BFS:


#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># Include<cmath> #define INF 0x7fffffff#define EPS 1e-6#define LL long longusing namespace std;struct lx{int ans,lv ;};    int ans[2051];int value[7];void BFS () {queue<lx>q;    BOOL vis[2051];    memset (vis,0,sizeof (VIS));    LX now,tmp;    tmp.ans=0,tmp.lv=0;    Q.push (TMP);    Vis[0]=1;        while (!q.empty ()) {Tmp=q.front (); Q.pop ();        ans[tmp.ans]=tmp.lv;            for (int i=0;i<6;i++) {int num1=tmp.ans+value[i];            int num2=tmp.ans-value[i];            now.lv=tmp.lv+1;                if (!vis[num1]&&num1>0&&num1<2000) {vis[num1]=1;                NOW.ANS=NUM1;            Q.push (now);          } if (!vis[num2]&&num2>0&&num2<2000)  {vis[num2]=1;                now.ans=num2;            Q.push (now);    }}}}int Main () {int t;    scanf ("%d", &t);        while (t--) {for (int i=0; i<6; i++) scanf ("%d", &value[i]);        BFS ();        Double an=0;        int maxn=0;            for (int i=1;i<=100;i++) {an+=ans[i];        Maxn=max (Maxn,ans[i]);//printf ("%d:%d\n", i,ans[i]);    } printf ("%.2f%d\n", AN/100,MAXN); }}


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

POJ 1252 Euro Efficiency

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.