0 点赞 评论 收藏
分享
牛客855512997号:第一题用的二分,0.7
投递百度等公司10个岗位 >
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
咕咕咕_:拒绝长代码(雾 #include <bits/stdc++.h>
using namespace std;
int sqr(int x) {return x * x;}
void chmin(int &x, int y) {if (x > y) x = y;}
int dp[1 << 20], n, m, a[21], vis[1 << 20], S, ans;
char s[25];
int main() {
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> s;
for (int j = 0; j < m; ++j) if (s[j] == '1') a[i] |= 1 << j;
}
for (int S = 0; S < (1 << n); ++S)
for (int i = 0; i < n; ++i) if (S & (1 << i)) vis[S] |= a[i];
memset(dp, 0x3f, sizeof dp);
dp[0] = 0;
for (int S = 0; S < (1 << n); ++S) {
for (int i = 0; i < n; ++i)
if (!(S & (1 << i))) chmin(dp[S | (1 << i)], dp[S] +
sqr(__builtin_popcount(vis[S | (1 << i)] ^ (vis[S | (1 << i)] & vis[S]))));
}
cout << dp[(1 << n) - 1];
return 0;
}
0 点赞 评论 收藏
分享
关注他的用户也关注了: