結果

問題 No.733 分身並列コーディング
ユーザー mnti-q
提出日時 2024-09-18 09:43:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 179 ms / 1,500 ms
コード長 1,599 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 194,948 KB
最終ジャッジ日時 2025-02-24 09:16:17
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,a,b)for(int i=a;i<b;i++)
#define rrep(i,a,b)for(int i=a;i>b;i--)
#define R(a) rep(i,0,a)
#define RR(a,b) rep(i,0,a)rep(j,0,b)
#define RRR(a,b,c) RR(a,b)rep(k,0,c)
#define el '\n'
#define YN(p) cout << (p?"Yes":"No") << el;
#define SU(p) cout << p << el;
#define PU(p) cout << p.first << ' ' << p.second << el;
#define VU(p) R(p.size())cout << p[i] << (i!=p.size()-1?' ':el);
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define Toup(s) transform(all(s),s.begin(),[](char c){return toupper(c);})
#define Tolow(s) transform(all(s),s.begin(),[](char c){return tolower(c);})
#define fix() cout << fixed << setprecision(12);
using ll = long long;
const int inf = 1073041824;
const ll INFL=1LL<<60;
const ll mod= 998244353;
const ll MOD=1000000007;
bool ok=false;
const int fj[4]={0,1,0,-1};//上右下左
const int fi[4]={-1,0,1,0};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n,m;
    cin >> m >> n;;
    vector<int>a(n);
    R(n)cin >> a[i];
    vector<int>dp(1<<n,inf);
    bitset<20>b;
    R(1<<n){
        if(i==0)continue;
        b=i;
        if(b.count()==1){
            dp[i]=1;
            continue;
        }
        int sum=0;
        ok=true;
        rep(j,0,n){
            if(i&(1<<j))sum+=a[j];
            if(sum>m){
                ok=false;
                break;
            }
        }
        if(ok)dp[i]=1;
        else {
            for(int j=i;j>0;j=(j-1)&i){
                dp[i]=min(dp[i],dp[j]+dp[i^j]);
            }
        }
    }
    SU(dp[(1<<n)-1])
}
0