Aizu 0525(Osenbei 穷竭搜索)
来源:互联网 发布:nba季后赛各项数据统计 编辑:程序博客网 时间:2024/06/03 09:50
/* 翻煎饼,1正面朝上,0反面朝上, * 每次可翻某一行或者某一列 * 问最大正面朝上数 */#include<cstdio>#include<iostream>#include<vector>#include<map>#include<set>#include<queue>#include<algorithm>#include<string>#include<cstring>#include<cstdlib>#include<cctype>#include<sstream>#include<stack>#include<functional>using namespace std;typedef long long ll;typedef pair<int, int> P;const int INF=0x3f3f3f3f;const int MAX_N = 10000;int G[10][MAX_N];int R, C;int ans;//反转r行void turn(int r){ for(int i = 0; i < C; i++) G[r][i] = !G[r][i];}//计算当前操作后,煎饼朝上的数目int num(){ int res = 0; for(int i = 0; i < C; i++){ int t = 0; for(int j = 0; j < R; j++){ if(G[j][i])t++; } res += max(t, R - t); } return res;}//行数较少,只用考虑行的翻转,每列只考虑翻转或者不翻转//这在num()体现出来void dfs(int r){ if(r >= R){ ans = max(ans, num()); return; } turn(r); dfs(r + 1); //翻当前行 turn(r); dfs(r + 1); //不翻当前行}int main(){#ifdef LOCALfreopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);#endif//ios::sync_with_stdio(false);while(cin >> R >> C && (R || C)){ ans = -INF; for(int i = 0; i < R; i++) for(int j = 0; j < C; j++) scanf("%d", &G[i][j]); dfs(0); cout << ans << endl;}return 0;}
0 0
- Aizu 0525(Osenbei 穷竭搜索)
- AOJ-0525 Osenbei-翻煎饼(穷竭搜索,BFS,BITSET)
- Aizu 0525 Osenbei【枚举+dfs】
- Osenbei Aizu
- [搜索or枚举]AOJ 0525 Osenbei
- 穷竭搜索
- 穷竭搜索
- 穷竭搜索
- 穷竭搜索
- dfs 简单穷竭搜索。AOJ 0525
- poj1852 Ants 穷竭搜索
- (七)穷竭搜索
- poj3187 穷竭搜索
- POJ 2718 -- 穷竭搜索
- 算法之穷竭搜索
- POJ3050-Hopscotch-穷竭搜索
- 2.1穷竭搜索
- Aoj 0525 Osenbei
- centos7下yum安装mysql与卸载mysql
- c++作业2
- linux教程:配置Tomcat开机启动 centos7
- 单例模式
- 对一个才子的走访我学到了什么?
- Aizu 0525(Osenbei 穷竭搜索)
- python 元类的使用(orm框架搭建)
- 克服当众表达的恐惧心理-《卡耐基语言的突破与相处的艺术》(美)卡耐基
- 【转载】在Windows下Memcache缓存系统构建(Java)
- android异步加载网络图片(1)
- 网络编程练习------简单双机通讯
- Launcher源码运行报错问题
- 匈牙利算法
- 采用dlopen、dlsym、dlclose加载动态链接库