2018 ACM-ICPC, Syrian Collegiate Programming Contest F - Pretests SOS dp
2024-08-24 13:10:01
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int T, m, n, up, dp2[<<], dp[<<], pre[<<];
char s[];
vector<int> ans; int main() {
// freopen("tests.in", "r", stdin);
scanf("%d", &T);
while(T--) {
ans.clear();
scanf("%d%d", &m, &n);
up = << m;
for(int i = ; i < up; i++) dp2[i] = , dp[i] = inf;
for(int i = ; i < n; i++) {
scanf("%s", s); int x = ;
for(int j = ; j < m; j++)
if(s[j] == '') x += << j;
dp2[x]++;
}
for(int i = ; i < m; i++)
for(int s = ; s < up; s++)
if(s>>i&) dp2[s^(<<i)] += dp2[s];
dp[] = ;
for(int s = ; s < up; s++) {
for(int i = ; i < m; i++) {
if(s>>i&) continue;
int nexs = s | (<<i);
if(dp[s]+dp2[s] < dp[nexs]) {
dp[nexs] = dp[s]+dp2[s];
pre[nexs] = s;
}
}
}
int nows = up-, nexs;
while(nows) {
nexs = pre[nows];
int xo = nexs ^ nows;
for(int i = ; i < m; i++) {
if(<<i == xo) {
ans.push_back(i+);
break;
}
}
nows = nexs;
}
reverse(ans.begin(), ans.end());
printf("%d\n", dp[up-]);
for(int t : ans) printf("%d ", t);
puts("");
}
return ;
}
/*
*/
最新文章
- HTTP权威指南-基础知识
- java多线程-读写锁
- DOM--2 创建可重用的对象
- webshell
- mysql及redis环境部署时遇到的问题解决
- JavaScript DOM高级程序设计 4.3控制事件流和注册事件侦听器--我要坚持到底!
- (转)IOS 学习笔记 2015-03-23 如何获取IOS程序的系统信息
- Unity 图片的灰度处理
- ContentProvider中的数据生成时机
- Java中取某一个范围的随机数
- 【转载】Stack Overflow: The Architecture - 2016 Edition
- Excel单元格所在的行和列变色
- HTML,JS禁止鼠标右键、禁止全选、复制、粘贴的方法
- SQL优化及注意事项
- ST-LINK V2 DIY笔记(一)
- python基础(1)
- JSP报错:The superclass ";javax.servlet.http.HttpServlet"; was not found on the Java Build Path
- python 前面几个单词含义
- Eclipse中jsp和html格式化自动排版问题
- JS循环语句!