时间限制:1000MS  内存限制:65535K
提交次数:0 通过次数:0

题型: 编程题   语言: C++;C

Description

As every one known, a football team has 11 players . Now, there is a big problem in front of the Coach Liu. The final contest is getting closer.
Who is the center defense, the full back or the forward? ...... There are n wonderful players for n positions in the team and Coach Liu know
everyone's abilities at different positions in matches. Assume that the team's power is the sum of the abilities of all n players according to
their positions, could you help Coach Liu to find out the max power his team can get?

输入格式

The first line is an integer n(n<11). Followed by n rows. Each row has n integer (0 to 1000) which represents the abilities of one player
at different positions.

输出格式

The max power.

输入样例

10
4 6 3 3 4 5 7 4 9 0
5 9 3 4 6 1 7 3 9 3
1 5 8 0 5 4 2 7 9 3
4 6 9 4 7 3 7 9 5 4
2 0 1 3 2 5 8 4 6 2
1 5 8 4 2 6 8 0 4 2
1 4 2 6 8 9 4 2 6 8
1 2 9 5 6 4 2 7 5 7
2 4 7 5 8 5 3 2 6 4
2 4 6 4 8 7 3 5 7 3

输出样例

76

简单回溯:wa在由于now是全局变量,在每一次到达结束状态时,now的值不会因递归返回而改变(不像局部变量),而我是希望在递归枚举所有情况是now的值应该是返回上一状态的,
故因 加一句:now-=mat[i][j]
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int mat[12][12];
int vis[12];
int now=0;
int maxr=0;
void dfs(int cur)
{
int i;
if(cur==n) {if(now>maxr) maxr=now;}
else for(i=0;i<10;++i){
if(!vis[i]){
now+=mat[cur][i];//尝试选择第cur行第i列的数
vis[i]=1;
dfs(cur+1);
vis[i]=0;
now-=mat[cur][i];//谨记,now需随递归返回原来的值
} }
}
int main()
{
memset(vis,0,sizeof(vis));
memset(mat,0,sizeof(mat));
scanf("%d",&n);
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
scanf("%d",&mat[i][j]);
dfs(0);
printf("%d\n",maxr);
}

最新文章

  1. ubuntu install eclipse-installer
  2. 针对bootstrap内联单选框input与文字不能居中对齐的解决办法
  3. javascript面试题(一)
  4. MFC重载关闭按钮
  5. android中scrollTo和scrollBy的理解
  6. 做好织梦dedecms安全防护全部方法
  7. UVA 1839 Alignment
  8. if __name__ == &#39;__main__&#39; 到底是何方神圣(转)
  9. BZOJ_4448_[Scoi2015]情报传递_主席树
  10. openstack搭建之-nova配置(10)
  11. Flask插件wtforms、Flask文件上传和Echarts柱状图
  12. 用Flask+Redis维护Cookies池
  13. 【Mysql】事务的四种特性和隔离级别
  14. Don&#39;t forget to Cherish
  15. linux常用命令:cp 命令
  16. Kali linux apt-get update 失败,无release……(最有效)
  17. 匿名函数lambda,过滤函数filter,映射类型map
  18. day29 python 套接字socket TCP udp 形式发送信息的区别
  19. [Microsoft][ODBC Microsoft Access Driver] 参数不足,期待是 1
  20. 唯一索引 &amp;&amp; 主键索引

热门文章

  1. centos安装配置nginx
  2. C++中new的解说
  3. 坚持不懈之linux haproxy 配置文件 详情
  4. Redis windows安装配置与Jedis访问数据库
  5. 《ASP.NET1200例》实现投票的用户控件
  6. process vs thread
  7. centos下编译安装mysql5.5/5.6
  8. POJ 2549 Sumsets hash值及下标
  9. BestCoder17 1001.Chessboard(hdu 5100) 解题报告
  10. HDU 1521 排列组合 指数型母函数