背包 要么 BFS

意大利是说给你几个基本的货币,组成 1~100 所有货币,使用基本上的货币量以最小的。

出口 用法概率。和最大使用量。

能够BFS 有可能 。

只是记得数组开大点。 可能会出现 100 = 99+99 -98 的情况。

背包是先做一个全然背包,求得最少可能由多少相加。

然后做一个 01背包,看是否能被 减。

背包:

#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 long
using 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 long
using 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);
}
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

POJ 1252 Euro Efficiency的更多相关文章

  1. POJ 1252 Euro Efficiency(完全背包, 找零问题, 二次DP)

    Description On January 1st 2002, The Netherlands, and several other European countries abandoned the ...

  2. POJ 1252 Euro Efficiency(最短路 完全背包)

    题意: 给定6个硬币的币值, 问组成1~100这些数最少要几个硬币, 比如给定1 2 5 10 20 50, 组成40 可以是 20 + 20, 也可以是 50 -10, 最少硬币是2个. 分析: 这 ...

  3. POJ 1252 Euro Efficiency ( 完全背包变形 && 物品重量为负 )

    题意 : 给出 6 枚硬币的面值,然后要求求出对于 1~100 要用所给硬币凑出这 100 个面值且要求所用的硬币数都是最少的,问你最后使用硬币的平均个数以及对于单个面值所用硬币的最大数. 分析 :  ...

  4. POJ Euro Efficiency 1252

    Euro Efficiency Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4109   Accepted: 1754 D ...

  5. Euro Efficiency(完全背包)

    Euro Efficiency Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Tot ...

  6. POJ 1252 DP

    题意:给你6个数.让你求出1~100范围内的数 最优情况下由这六个数加减几步得到. 输出平均值和最大值. 思路: 我就随便写了写,,,感觉自己的思路完全不对. 但是交上去 AC了!!! 我先当减法 不 ...

  7. POJ 3260 The Fewest Coins(多重背包+全然背包)

    POJ 3260 The Fewest Coins(多重背包+全然背包) http://poj.org/problem?id=3260 题意: John要去买价值为m的商品. 如今的货币系统有n种货币 ...

  8. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  9. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

随机推荐

  1. TCP header

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3Vzc2VyNDM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...

  2. crontab,想说爱你不easy

    悲剧的背景 跑自己主动化脚本的机器连不上toastserver了, 仅仅能自己写个脚本每天跑了. 当然要放在crontab里了. 5 3 * * * sh ~/nosecron.sh 更悲剧的结果 第 ...

  3. 【原创】leetCodeOj --- Binary Search Tree Iterator 解题报告

    时间挤挤总是有的 太久不做题,脑子都生锈了.来道水题练练手 题目地址: https://leetcode.com/problems/binary-search-tree-iterator/ 题目内容: ...

  4. Eclipse 在线安装fat jar插件

    在线安装步骤: eclipse菜单栏 help >software updates >Search for new features to install>new update si ...

  5. .net机试题总结

    1.下面是一个由*号组成的4行倒三角形图案.要求:1.输入倒三角形的行数,行数的取值3-21之间,对于非法的行数,要求抛出提示“非法行数!”:2.在屏幕上打印这个指定了行数的倒三角形. ******* ...

  6. cocos2dx 遮罩层 android 手机上 失败

    1.CCClippingNode使用(在模拟器上ok,在手机上不行),实现多个剪切区域 local layer=CCLayerColor:create(ccc4(0,0,0,110))     --/ ...

  7. Unbound classpath container: &#39;JRE System Library [jdk17060]&#39; in project ***

    项目报告的错误列表 Unbound classpath container: 'JRE System Library [jdk17060]' in project **** 误. 原因是,我升级JDK ...

  8. NET WEB

    .NET WEB程序员需要掌握的技能 2015-12-28 08:50 by 敏捷的水, 3997 阅读, 66 评论, 收藏, 编辑 本来这个是我给我们公司入职的新人做一个参考,由于 @张善友 老师 ...

  9. WPF技术触屏上的应用系列(五): 图片列表异步加载、手指进行缩小、放大、拖动 、惯性滑入滑出等效果

    原文:WPF技术触屏上的应用系列(五): 图片列表异步加载.手指进行缩小.放大.拖动 .惯性滑入滑出等效果 去年某客户单位要做个大屏触屏应用,要对档案资源进行展示之用.客户端是Window7操作系统, ...

  10. org.apache.jasper.JasperException: An exception occurred processing JSP page /admin/jiaoshi/daochuEx

    org.apache.jasper.JasperException: An exception occurred processing JSP page /admin/jiaoshi/daochuEx ...