POJ 1252 Euro Efficiency
背包 要么 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的更多相关文章
- POJ 1252 Euro Efficiency(完全背包, 找零问题, 二次DP)
Description On January 1st 2002, The Netherlands, and several other European countries abandoned the ...
- POJ 1252 Euro Efficiency(最短路 完全背包)
题意: 给定6个硬币的币值, 问组成1~100这些数最少要几个硬币, 比如给定1 2 5 10 20 50, 组成40 可以是 20 + 20, 也可以是 50 -10, 最少硬币是2个. 分析: 这 ...
- POJ 1252 Euro Efficiency ( 完全背包变形 && 物品重量为负 )
题意 : 给出 6 枚硬币的面值,然后要求求出对于 1~100 要用所给硬币凑出这 100 个面值且要求所用的硬币数都是最少的,问你最后使用硬币的平均个数以及对于单个面值所用硬币的最大数. 分析 : ...
- POJ Euro Efficiency 1252
Euro Efficiency Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4109 Accepted: 1754 D ...
- Euro Efficiency(完全背包)
Euro Efficiency Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Tot ...
- POJ 1252 DP
题意:给你6个数.让你求出1~100范围内的数 最优情况下由这六个数加减几步得到. 输出平均值和最大值. 思路: 我就随便写了写,,,感觉自己的思路完全不对. 但是交上去 AC了!!! 我先当减法 不 ...
- POJ 3260 The Fewest Coins(多重背包+全然背包)
POJ 3260 The Fewest Coins(多重背包+全然背包) http://poj.org/problem?id=3260 题意: John要去买价值为m的商品. 如今的货币系统有n种货币 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
随机推荐
- Effective C++ Item 33 避免遮掩继承过来的名称
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie ? 不懂 c++为什么derived classes 内的名称要遮掩 base classe ...
- Makefile 管理工具 — Automake and Autoconf
该project下载路径:http://files.cnblogs.com/iTsihang/hello-2.0.zip automake 參考资料:http://www.linuxforum.net ...
- Swift难点-继承中的构造规则实例具体解释
关于继承中的构造规则是一个难点. 假设有问题,请留言问我. 我的Swift新手教程专栏 http://blog.csdn.net/column/details/swfitexperience.html ...
- 建立Hibernate二级Cache
建立Hibernate二级Cache它需要两个步骤:首先,一定要使用什么样的数据并发策略,然后配置缓存过期时间,并设置Cache提供器. 有4种内置的Hibernate数据并发冲突策略,代表数据库隔离 ...
- 再说JNDI
说到JNDI,即熟悉又陌生,熟悉在常常使用,如EJB3.0中的@EJB注入,底层实现即是JNDI的方式:喜闻乐见的: Context ctx=new InitialContext(); Object ...
- 重新想象 Windows 8 Store Apps (31) - 加密解密: 哈希算法, 对称算法
原文:重新想象 Windows 8 Store Apps (31) - 加密解密: 哈希算法, 对称算法 [源码下载] 重新想象 Windows 8 Store Apps (31) - 加密解密: 哈 ...
- SendMail如何签名
MailAddress类有两个参数 第1个参数:发送者的邮箱 第2个参数:发送者的签名 示例: MailMessage message = new MailMessage();message.From ...
- LA3026 - Period(KMP)
For each prefix of a given string S with N characters (each character has an ASCII code between 97 a ...
- JAVA Socket超时浅析(转)
套接字或插座(socket)是一种软件形式的抽象,用于表达两台机器间一个连接的“终端”.针对一个特定的连接,每台机器上都有一个“套接字”,可以想象它们之间有一条虚拟的“线缆”.JAVA有两个基于数据流 ...
- retry policy is RetryUpToMaximumCountWithFixedSleep(maxRetries=10, sleepTime=1 SECONDS)
[root@qa bin]# hadoop fs -ls / Warning: $HADOOP_HOME is deprecated. 14/07/29 13:25:35 INFO ipc.Clien ...