Interact


私信TA

用户名:Interact

访问量:22009

签 名:

等  级
排  名 654
经  验 3891
参赛次数 0
文章发表 31
年  龄 0
在职情况 学生
学  校 哈尔滨理工大学
专  业

  自我简介:

组 合 数 学 靠 运 气 计 算 几 何 瞎 暴 力 图 论 一 顿 套 模 板 模 拟 只 会 猜 题 意 贪 心 只 能 过 样 例

解题思路:





注意事项:





参考代码:

#include<string>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<sstream> 
#include<cstdlib>
#include<iomanip>
using namespace std;
const int MAX=100000000;
int num[7][7];
int result[7][7];
int output;
void dfs(int t,int n){//深度优先
    if(t==n){
        int max=-100000000,temp;
        for(int j=0;j<n;j++)
        {
            temp=0;
            for(int i=0;i<n;i++)
                temp+=result[i][j];
            if(temp>max)
                max=temp;
        }
        //cout<<max<<endl;
        if(max<output)
            output=max;
        return;
    }
    for(int i=0;i<n;i++){//每次移动位置数
        for(int j=0;j<n;j++)
            result[t][(j+i)%n]=num[t][j];
        dfs(t+1,n);
    }
}
int main(){
    int n;
    while(cin>>n){
        if(n==-1)break;
        output=MAX;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                cin>>num[i][j];
        dfs(0,n);
        cout<<output<<endl;
    }
    return 0;
}

 

0.0分

3 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区