Submission #00023


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int n;
int a[105];
long long dp[105][1005];
long long f(int pos,int sum){
if(dp[pos][sum]!=-1)return dp[pos][sum];
if(pos==n-1){
if(sum==a[n-1])return 1;
else return 0;
}
if(sum-a[pos]>=0){
if(sum+a[pos]<=20){
return dp[pos][sum]=f(pos+1,sum+a[pos])+f(pos+1,sum-a[pos]);
}else{
return dp[pos][sum]=f(pos+1,sum-a[pos]);
}
}else{
return dp[pos][sum]=f(pos+1,sum+a[pos]);
}
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
memset(dp,-1,sizeof(dp));
cout<<f(1,a[0])<<"\n";
return 0;
}

ステータス

項目 データ
問題 0002 - 1年生 (A First Grader)
ユーザー名 ei1832
投稿日時 2019-10-30 17:09:52
言語 C++
状態 Accepted
得点 100
ソースコード長 708 Byte
最大実行時間 28 ms
最大メモリ使用量 1416 KB

セット

セット 得点 Cases
1 入力1 20 / 20 *1.txt
2 入力2 20 / 20 *2.txt
3 入力3 20 / 20 *3.txt
4 入力4 20 / 20 *4.txt
5 入力5 20 / 20 *5.txt

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
2011-yo-t4-in1.txt AC 24 ms 1368 KB
1
2011-yo-t4-in2.txt AC 22 ms 1416 KB
2
2011-yo-t4-in3.txt AC 28 ms 1332 KB
3
2011-yo-t4-in4.txt AC 19 ms 1368 KB
4
2011-yo-t4-in5.txt AC 19 ms 1284 KB
5