結果
| 問題 | 
                            No.5 数字のブロック
                             | 
                    
| コンテスト | |
| ユーザー | 
                             takatowin
                         | 
                    
| 提出日時 | 2017-01-06 23:19:40 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 530 bytes | 
| コンパイル時間 | 310 ms | 
| コンパイル使用メモリ | 31,232 KB | 
| 実行使用メモリ | 8,744 KB | 
| 最終ジャッジ日時 | 2024-12-17 14:55:02 | 
| 合計ジャッジ時間 | 127,675 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 9 WA * 4 TLE * 21 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |   scanf("%d %d",&L,&N);
      |   ~~~~~^~~~~~~~~~~~~~~
main.cpp:28:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |     scanf("%d",&b[i]);
      |     ~~~~~^~~~~~~~~~~~
            
            ソースコード
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int L,N;
int max(int a,int b){
  if(a>b)
    return a;
  else
    return b;
}
int saiki(int temp,int f,int* b,int n){
  int i=0;
  if(f>L)
    return temp-1;
  else{
    if(n!=0)
      return max(saiki(temp,f,b,n-1),saiki(temp+1,f+b[N-n],b,n-1));
    else
      return temp; 
  }
}
int main(void){
  int i=0;
  scanf("%d %d",&L,&N);
  int b[N];
  for(;i<N;i++){
    scanf("%d",&b[i]);
  }
  printf("%d\n",max(saiki(0,0,b,N),saiki(1,b[0],b,N)));
return 0;
}
            
            
            
        
            
takatowin