結果

提出番号 2043
提出者 dohatsutsu
言語 C++
提出日時 2018-08-04 15:03:01
問題名 (66)Cut onion
結果 TLE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 2ms 7824KB
2 AC 100% 2ms 7824KB
3 AC 100% 2ms 7632KB
4 AC 100% 2ms 8400KB
5 AC 100% 2ms 7840KB
6 AC 100% 2ms 8096KB
7 AC 100% 2ms 8432KB
8 AC 100% 95ms 8112KB
9 AC 100% 2ms 8112KB
10 AC 100% 47ms 7504KB
11 AC 100% 5ms 8704KB
12 AC 100% 2ms 8400KB
13 TLE 0% 9029ms 7632KB
14 AC 100% 2ms 8000KB
15 AC 100% 352ms 8112KB
16 AC 100% 2ms 8704KB
17 AC 100% 2ms 7504KB
18 AC 100% 225ms 8416KB
19 AC 100% 1128ms 8256KB
20 AC 100% 2ms 7824KB

ソースコード

#include<bits/stdc++.h>
using namespace std;
int N,K,B;
int A[16];

int limit;
bool dfs(int x,int c,int t[16],int sz,int cost){
  if(cost>limit)return false;
  if(x==N)return true;

  if( A[x] <= 0 )return dfs(x+1,c,t,sz,cost);
  
  int tmp[16];
  for(int i=0;i<sz;i++)tmp[i]=t[i];
  
  for(int i=0;i<sz;i++){
    int u=t[i];
    A[x] -= u;
    swap(t[i],t[sz-1]);
    if( dfs(x,c,t,sz-1,cost) )return true;
    A[x] += u;

    for(int j=0;j<sz;j++)t[j]=tmp[j];
      
    if(t[i]>A[x]){
      t[i]-=A[x];
      if( dfs(x+1,c,t,sz,cost+1) )return true;
      t[i]+=A[x];
    }
  }
  
  if(c>0){
    if( dfs(x+1, c-1,t,sz,cost) )return true;
    t[sz]=B-A[x];
    if( dfs(x+1, c-1,t,sz+1,cost+1) )return true;
  }

  return false;
}

int main(){
  cin>>N>>K>>B;
  for(int i=0;i<N;i++)cin>>A[i];
  int t[16];
  
  for( limit = 0; limit <=14; limit ++){
    if( dfs(0,K,t,0,0) ){
      cout<<limit<<endl;
      return 0;
    }
  }
  
  cout<<15<<endl;
  return 0;
}