国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

母函數解決 Jam's balance hdu5616

2019-11-08 02:47:10
字體:
來源:轉載
供稿:網友

Jam's balance

Time Limit: 2000/1000 MS (java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1572    Accepted Submission(s): 669PRoblem DescriptionJim has a balance and N weights. (1≤N≤20)The balance can only tell whether things on different side are the same weight.Weights can be put on left side or right side arbitrarily.Please tell whether the balance can measure an object of weight M. InputThe first line is a integer T(1≤T≤5), means T test cases.For each test case :The first line is N, means the number of weights.The second line are N number, i'th number wi(1≤wi≤100) means the i'th weight's weight is wi.The third line is a number MM is the weight of the object being measured. OutputYou should output the "YES"or"NO". Sample Input
121 43245 Sample Output
NOYESYESHintFor the Case 1:Put the 4 weight aloneFor the Case 2:Put the 4 weight and 1 weight on both side  

題母的 意思是  給 幾個砝碼    砝碼 可以放在天平的 兩邊 或者一邊 ,  問你 給你幾個 測試數據 砝碼 能否 恰好 稱出 這個數據 

這個 題 解法有多種  , 我用的母函數 : 

模板一:

//1.0:母函數 解決 模板一 #include<stdio.h>#include<stdlib.h>#include<string.h>#define abs(x) ((x)<0? -(x):(x))// - 一定要在()外 int a[2015],b[2015];int v[2015];int main(){	int T,n,m;	int i,j,k,kk;	while(~scanf("%d",&T))	{		while(T--)		{			int sum=0;			memset(v,0,sizeof(v));//清零操作			memset(a,0,sizeof(a));			memset(b,0,sizeof(b));			scanf("%d",&n);			for(i=1;i<=n;i++)			{				scanf("%d",&v[i]);				sum+=v[i];			}			a[v[1]]=a[0]=1;//初始 化  			for(i=2;i<=n;i++)//次數 			{				memset(b,0,sizeof(b)); //╮(╯_╰)╭進行一次 就  初始為0 				for(j=0;j<=sum;j++)// 每個 v[]  				{					for(k=0;k+j<=sum&&k<=v[i];k+=v[i])//每個a 					{						b[k+j]+=a[j];//天平一邊 						b[abs(k-j)]+=a[j];//天平兩邊 					}				}				memcpy(a,b,sizeof(b));				}				scanf("%d",&m);//			printf("abs=%d/n",abs(5-6));//			for(i=0;i<sum;i++)//				{//					printf("%d /n",a[i]);//				//				}			while(m--)			{				scanf("%d",&kk);				if(a[kk])				{					printf("YES/n");				}				else				{					printf("NO/n");				}			}				}	}	return 0;}


上一篇:簡易的自定義鬧鐘

下一篇:PAT-DAY-2

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永登县| 绥德县| 仁怀市| 新民市| 池州市| 鄂尔多斯市| 荣成市| 长兴县| 修文县| 织金县| 会宁县| 高平市| 山阳县| 凭祥市| 安徽省| 运城市| 开远市| 天峨县| 山东省| 定西市| 视频| 蓬莱市| 台山市| 隆昌县| 赫章县| 新竹县| 天气| 都安| 保定市| 剑川县| 泗水县| 黄浦区| 信丰县| 怀集县| 甘泉县| 胶南市| 西城区| 承德市| 灵台县| 湖北省| 吉安县|