K.Teamwork Brings Profits! 典型的dfs搜索
来源:互联网 发布:软件使用授权书模板 编辑:程序博客网 时间:2024/06/05 16:53
K.Teamwork Brings Profits!
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 117 Accepted Submission(s) : 53
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Williammed's father is running a small company now, which has N employees.(2<=N<=10 and N is an even number). The employees are numbered from 1 to N. All the employees are divided into N/2 groups. One employee can only be in one group, and each group works on one project. As we all know, teamwork is very important to a company, so different team can make different profits. And now, given any two people i and j, Williammed's father can tell how much profit(Pij) can they make if they work together. Here comes the problem, given all the Pij(1 <= i <= N,1 <= j <= N,0 < Pij<= 100), you should tell the most profits this company can make. This is an easy problem, isn't it?
Input
The first line of the input is N(2<=N<=10 and N is an even number),the number of employees in the company.
Then there're N lines,each line has N numbers.The jth number in the ith line is Pij,as we discribe above.And we guarantee Pij = Pji,Pii = 0.
The end-of-file is denoted by a single line containing the integer 0.
Then there're N lines,each line has N numbers.The jth number in the ith line is Pij,as we discribe above.And we guarantee Pij = Pji,Pii = 0.
The end-of-file is denoted by a single line containing the integer 0.
Output
For each case,output the most profits this company can make.
Sample Input
40 6 62 136 0 35 9462 35 0 513 94 5 00
Sample Output
156
Author
Source
Developing School's Contest 6
post code:
直接进行dfs搜索就可以了
#include<stdio.h>#include<string.h>int a[12][12];int visit[12];int max,t,sum,n;void dfs( int time ,int sum){ if(time==t){if(max<sum)max=sum;return;} int i,j; for(i=1;i<=n-1;i++) for(j=i+1;j<=n;j++) { if(visit[i]==false&&visit[j]==false) { visit[i]=visit[j]=true; //记录此点已经搜索过了 dfs(time+1,sum+a[i][j]); visit[i]=visit[j]=false; //将此点变成未搜索过。 } } }int main(){ int i,j; while(scanf("%d",&n)&&n!=0) { max=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%d",&a[i][j]); t=n/2; memset(visit,false,sizeof(visit)); dfs(0,0); printf("%d\n",max); } }
- K.Teamwork Brings Profits! 典型的dfs搜索
- HLJU 1036: Teamwork Brings Profits! (dfs)
- hdu 1312 DFS深度搜索典型例题
- nyoj+dfs搜索+vector二维数组+典型的递归模板需要慢慢领悟
- 典型的Top K算法
- 典型的Top K算法
- 我心中的Teamwork
- poj 3984 迷宫问题 —— 典型搜索--DFS递归
- poj 3984 迷宫问题 —— 典型搜索--DFS递归
- 133. Clone Graph :一个典型的DFS
- leetcode 395. Longest Substring with At Least K Repeating Characters 最长K个数量的字符 + DFS深度优先搜索
- 百练+DFS+就是一个典型的DFS框架
- 分治法的典型例子 --- 二分搜索
- NYOJ-325-zb的生日(典型搜索)
- 风险度量 典型的深度搜索
- 朴素搜索dfs, 简单的剪枝搜索
- 典型K线形态
- 典型Top K算法
- vc try catch捕捉所有异常的问题
- if条件里有两个 或 (||) 符号
- 单元测试与main前运行函数__attribute__((constructor))关键字
- C# Dictionary序列化/反序列化
- ReportViewer 嵌套子报表
- K.Teamwork Brings Profits! 典型的dfs搜索
- 在操作数据库时候出现 sqlite3_open_v2("/data/data/xxx/databases/xxx.db", &handle, 6)failed
- oracle 怎么查看一个数据库中有几个表空间?以及这些表空间的名字?
- 为什么要去火星
- sql server 2000更新技巧&select 查询中带参数,游标中使用exec
- chromium的gdb
- ftl语法
- memcached全面剖析–4. memcached的分布式算法
- php页面调用shell命令的问题