ZOJ 3010 The Lamp Game

14 篇文章 0 订阅
3 篇文章 0 订阅

这题我是用的bfs做的,用到一个map,用来统计是否访问过和最大值的保存

#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
struct Data
{
	int state;
	double score;
};
int main(){
	int i,j;
	int m,n;
	int re[12][12];
	int f[12];
	while(scanf("%d %d",&n,&m)!=EOF && n!=0){
		for(i=0;i<11;i++)
			for(j=0;j<11;j++)
				re[i][j]=-1;
		queue<Data> qqq;
		map<int,double> sss;
		for(i=0;i<n;i++){
			int t;
			scanf("%d",&t);
			for(j=0;j<t;j++){
				scanf("%d",&re[i][j]);
				re[i][j]--;
			}
			scanf("%d",&f[i]);
		}
		Data temp;
		temp.state=(1<<n)-1;
		temp.score=m;
		qqq.push(temp);
		sss[temp.state]=temp.score;
		sss[0]=-1.0;
		double res=-1;
		while(!qqq.empty()){
			temp=qqq.front();
			qqq.pop();
			for(i=0;i<n;i++){
				Data temp2=temp;
				j=0;
				temp2.state^=(1<<i);
				while(re[i][j]!=-1){
					temp2.state^=(1<<re[i][j]);
					j++;
				}
				temp2.score=temp2.score*(1.0-f[i]/100.0);
				if(sss.count(temp2.state)){
					if(sss[temp2.state]<temp2.score)
						sss[temp2.state]=temp2.score;
					continue;
				}
				qqq.push(temp2);
				sss[temp2.state]=temp2.score;
			}
		}
		if(sss[0]<=-1.0)
			printf("-1\n");
		else 
			printf("%.2lf\n",sss[0]);
		
	}
	return 0;
}
/*
3 100
0 50
0 50
2 1 2 50
0 0
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值