zoj 3010 The Lamp Game

Little Tom likes playing games. Recently he is fond of a game called Lamp Game. The game is like this: at first, there are n lamps on the desk, all of which are lighted and Tom is given an initial score. Each time, Tom selects one lamp and changes its state, this action will costs little Tom some percent of score. What's more, the circuit of the lamps is designed so that, when Tom changes the state of one lamp, some related lamps' states will also be changed. The object of this game is to make all lamps off and make the total lost of score as low as possible. Of course little Tom is not smart enough to solve this problem, so he asks you, a student in ZJU, to help him.

Input

The input contains several test cases. Each case begins with two integers n and m (n<=10,0<m<=100000000), which are the number of lamps and the initial score of Tom. Then n lines follows, each in the format of t n1 n2 ...... nt f (0<=t<n,1<=ni<=n,0<=f<100). The i-th line means changing the state of the i-th lamp will make t related lamps' states changed and the following t integers give the t related lamps (these t numbers will not include i). And changing the state of the i-th lamp will cost Tom f percents of score. All numbers are integers. Two 0s of n and m signals the end of input.

Output

For each test case, output one line containing the maximum score Tom has when he finished the game successfully. The result should be accurate to 2 decimal places. If Tom cannot finish this game, simply output -1.

Sample Input:

3 100
1 2 50
0 50
1 2 50
0 0

Sample Output

12.50
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define max(a,b) (a>b ? a:b)

int a[20][20],b[20],c[20];

int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF&&m)
	{
		int i,j,k,t;
		memset(a,0,sizeof(a));
		for(i=1;i<=n;i++) {
			scanf("%d",&t);
			for(j=0;j<t;j++) {
				scanf("%d",&k);
				a[k][i]=1;
			}
			a[i][i]=a[i][n+1]=1;
			scanf("%d",&b[i]);
		}
		int res=0;
		for(j=1;j<=n;j++) {
			for(i=j;i<=n;i++) {
				if(a[i][j]!=0) {
					if(i!=j)
					for(k=1;k<=n+1;k++) swap(a[i][k],a[j][k]);
					break;
				}
			}
			if(a[j][j]==0) {
				c[res++]=j;
				continue;
			}
			for(i=1;i<=n;i++) if(i!=j){
				for(k=n+1;k>=j;k--)
				  a[i][k]=(a[i][k]-a[i][j]/a[j][j]*a[j][k]+2)%2;
			}
		}
		for(i=n-res+1;i<=n;i++)
		  if(a[i][n+1]!=0) break;
		if(i<=n) {
			printf("-1\n");
			continue;
		}
		double ans=0,cnt;
		for(i=0;i<(1<<res);i++) {
			cnt=m;
			for(k=0;k<res;k++)
			  if((i&(1<<k))) cnt*=(1-b[c[k]]/100.0);
			for(j=1;j<=n-res;j++) {
				t=1;
				for(k=0;k<res;k++)
				  if((i&(1<<k))) t+=a[j][c[k]];
				if(t%2==a[j][n+1]) cnt*=(1-b[j]/100.0);
			}
			ans=max(ans,cnt);
		}
		printf("%.2lf\n",ans);
	}
	return 0;
}

心得:Guass消元时,当方程组有多解时,要注意那几个变量是任意的



1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.m或d论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 、1资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值