洛谷八连测r4t3
来源:互联网 发布:解码器和矩阵的区别 编辑:程序博客网 时间:2024/05/24 04:59
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,a[35][35],s[35][20],b[35],ans=-1,now[35];
void dfs(int x){
if(x==n+1){
int maxx=-1,max1=-1,cur,max2=0;
for(int i=1;i<=m;i++){
maxx=-1;
for(int k=0;k<3;k++){
max1=0;
for(int j=1;j<=n;j++){
cur=a[j][i]+now[j]+k;
//cout<<"cur: "<<cur<<' ';
if(cur==3||cur==6||cur==9||cur==12){
++max1;
}
}
maxx=max(max1,maxx);
//cout<<maxx<<' ';
}
max2+=maxx;
}
//cout<<endl;
if(max2>ans){
//cout<<max2<<": "<<endl;
//for(int i=1;i<=n;i++){
//cout<<now[i]<<' ';
//}
//cout<<endl;
ans=max2;
}
return ;
}
for(int i=0;i<3;i++){
now[x]=i;
dfs(x+1);
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&a[i][j]);
}
}
/*for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
cout<<a[i][j]<<' ';
cout<<endl;
}*/
dfs(1);
cout<<ans<<endl;
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,a[35][35],s[35][20],b[35],ans=-1,now[35];
void dfs(int x){
if(x==n+1){
int maxx=-1,max1=-1,cur,max2=0;
for(int i=1;i<=m;i++){
maxx=-1;
for(int k=0;k<3;k++){
max1=0;
for(int j=1;j<=n;j++){
cur=a[j][i]+now[j]+k;
//cout<<"cur: "<<cur<<' ';
if(cur==3||cur==6||cur==9||cur==12){
++max1;
}
}
maxx=max(max1,maxx);
//cout<<maxx<<' ';
}
max2+=maxx;
}
//cout<<endl;
if(max2>ans){
//cout<<max2<<": "<<endl;
//for(int i=1;i<=n;i++){
//cout<<now[i]<<' ';
//}
//cout<<endl;
ans=max2;
}
return ;
}
for(int i=0;i<3;i++){
now[x]=i;
dfs(x+1);
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&a[i][j]);
}
}
/*for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
cout<<a[i][j]<<' ';
cout<<endl;
}*/
dfs(1);
cout<<ans<<endl;
return 0;
}
阅读全文
0 0
- 洛谷八连测r4t3
- 洛谷八连测string
- 洛谷八连测r4t2
- 洛谷八连测r4t1
- 洛谷八连测r3t1
- 洛谷八连测R4
- 洛谷八连测 #R7
- 洛谷八连测 #R6
- 洛谷八连测 #R8
- T13735 fateice-string洛谷八连测2
- 洛谷八连测——关于取模与思维僵化
- JS中的数组
- c语言劫持技术
- adapert
- 【Shiro权限管理】4. Shiro工作流程
- 蓝牙搜索
- 洛谷八连测r4t3
- 按键精灵脚本笔记:基本语法
- 数据库视频总结(五)
- dao
- Linux安装
- 虚拟机中安装了Ubuntu,输入密码准备登陆时,登陆之后又弹回到登陆界面,无法进入系统
- snacks的模拟赛(t1)
- SocketChat通信
- React开发调试工具