結果

問題 No.437 cwwゲーム
ユーザー seven_three
提出日時 2020-07-14 22:39:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,791 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 101,380 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-19 01:10:02
合計ジャッジ時間 2,528 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int dp[1000][4400] = { 0 };
int main() {
string s;
cin >> s;
int n = s.size();
vector<pair<int, int>> vec;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
if (s[j] == s[k] && s[i] != s[j] && s[i] != '0') {
bitset<12> bit;
bit[i] = 1;
bit[j] = 1;
bit[k] = 1;
string s1 = "";
s1 += s[i];
s1 += s[j];
s1 += s[k];
int x = stoi(s1);
vec.emplace_back(make_pair(bit.to_ulong(), x));
}
}
}
}
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < (1 << n); j++) {
bool b = true;
bitset<12> bit = vec[i].first, bit1 = j;
for (int i = 0; i < 12; i++) {
if (bit[i] == 1 && bit1[i] == 1) {
b = false;
}
}
if (b) {
dp[i + 1][j | vec[i].first] = max(dp[i + 1][j | vec[i].first], dp[i][j] + vec[i].second);
}
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
int ans = 0;
for (int i = 0; i < (1 << n); i++) {
if (ans < dp[vec.size()][i]) {
ans = dp[vec.size()][i];
}
}
cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0