結果
問題 | No.437 cwwゲーム |
ユーザー |
![]() |
提出日時 | 2016-10-29 14:48:12 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,766 bytes |
コンパイル時間 | 1,553 ms |
コンパイル使用メモリ | 158,728 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 08:31:25 |
合計ジャッジ時間 | 2,691 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() #define CHMIN(a,b) a=min((a),(b)) #define CHMAX(a,b) a=max((a),(b)) // mod const ll MOD = 1000000007ll; #define FIX(a) ((a)%MOD+MOD)%MOD // floating typedef double Real; const Real EPS = 1e-11; #define EQ0(x) (abs(x)<EPS) #define EQ(a,b) (abs(a-b)<EPS) typedef complex<Real> P; /* N=a0a1…aL−1N=a0a1…aL−1 (10進数表記) I={0,1,...,L−1}I={0,1,...,L−1} score=0score=0 while true: Iから異なる3つの要素i, j, kを選ぶ (i<j<k)(i<j<k) x = a_i a_j a_k がcww数であるとき score += x Iからi, j, kを除く xがcww数となるようなi,j,kの選び方がなければ終了 */ string s; int l; int dp[1<<15]; int calc(int msk){ if(dp[msk]!=-1)return dp[msk]; dp[msk] = 0; REP(i,l)FOR(j,i+1,l)FOR(k,j+1,l){ if((msk>>i)&1){ if((msk>>j)&1){ if((msk>>k)&1){ if(s[i]!='0' && s[i]!=s[j] && s[j]==s[k]){ int adder = (s[i]-'0')*100 + (s[j]-'0')*11; int nmsk = msk ^ (1<<i) ^ (1<<j) ^ (1<<k); CHMAX(dp[msk],adder+calc(nmsk)); } } } } } return dp[msk]; } int main(){ cin>>s; l = s.size(); REP(i,1<<l)dp[i]=-1; int ans = calc((1<<l)-1); cout<<ans<<endl; return 0; }