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)递推. ...
随机推荐
- Shiro学习笔记(5)——web集成
Web集成 shiro配置文件shiroini 界面 webxml最关键 Servlet 測试 基于 Basic 的拦截器身份验证 Web集成 大多数情况.web项目都会集成spring.shiro在 ...
- java web开发人员经常使用标签
struts标签库 国际化配置 配置国际化 1.国际化配置 在struts自带的app中的struts-config.xml中的<message-resources parameter=&quo ...
- Error 56: The Cisco Systems, Inc. VPN Service has not been started(Cisco VPN在Vista下出现Error 56的解决办法)
Error 56: The Cisco Systems, Inc. VPN Service has not been started(Cisco VPN在Vista下出现Error 56的解决办法) ...
- (一个)kafka-jstorm集群实时日志分析 它 ---------kafka实时日志处理
package com.doctor.logbackextend; import java.util.HashMap; import java.util.List; import java.util. ...
- 新浪微博id的62进制转换
某条微博链接 某条微博的链接如下,同样省略了后面的无关参数 http://weibo.com/2803301701/CeaOU15IT CeaOU15IT为这条微博的mid,与之相对应的还有一个id, ...
- NYOJ 745 蚂蚁问题(两)
蚂蚁的难题(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 下雨了,下雨了.蚂蚁搬家了. 已知有n种食材须要搬走,这些食材从1到n依次排成了一个圈.小蚂蚁对每种 ...
- [LeetCode160]Intersection of Two Linked Lists
题目: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- Ehcache 整合Spring 使用页面、对象缓存(转)
Ehcache在很多项目中都出现过,用法也比较简单.一般的加些配置就可以了,而且Ehcache可以对页面.对象.数据进行缓存,同时支持集群/分布式缓存.如果整合Spring.Hibernate也非常的 ...
- 【LeetCode】【Python解读】Container with most water
这个问题是芭芭拉在采访中遇到的,不幸的是,的复杂性O(n2)该,太失望了,难怪没有通过面试. Given n non-negative integers a1, a2, ..., an, where ...
- Mongodb 之insert瞬时完成,测试数据---飞天博客
这几天看mongdb官方网站,然后将执行数据.突然,我发现,该数据确实很强大,在这里说话数据.我用普通的pc机,amd双核 2.7GHz,4G内存,当然,当系统不只是在测试作为数据库server的.同 ...