枚举+标记
2026-02-09 17:54:51
发布于:四川
4阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,a[20][20]={},max = 0,zzz = 0;//定义变量 zzz是拿来标记的
cin >> n;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
cin >> a[i][j];
}
}//输入
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){//暴力枚举 because n <= 10
if(a[i][j]==0){//如果可以站人
zzz = 10086;//标记一下
int sum = 0;
for(int x = 1;x <= n;x++){
sum += a[x][j];
}
for(int y = 1;y <= n;y++){
sum += a[i][y];
}//统计总和
if(sum > max){
max = sum;
}//判断是否是最大值
}
}
}
if(zzz == 0){//zzz有用了!
cout << "Bad Game!";
return 0;
}
cout << max;//判断+输出
return 0;
}
这里空空如也







有帮助,赞一个