From 3384d136deecc57d41f23ee11ade74668e564a65 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 18 Oct 2020 15:58:38 +0800 Subject: [PATCH] =?UTF-8?q?P1164=20=E5=B0=8FA=E7=82=B9=E8=8F=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R40041942 --- problem/P1164/P1164.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 problem/P1164/P1164.cpp diff --git a/problem/P1164/P1164.cpp b/problem/P1164/P1164.cpp new file mode 100644 index 00000000..21fafd18 --- /dev/null +++ b/problem/P1164/P1164.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +int main() { + int n, m, a[10005], f[10005][10005]; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (j == a[i]) { + f[i][j] = f[i - 1][j] + 1; + } + if (j > a[i]) { + f[i][j] = f[i - 1][j] + f[i - 1][j - a[i]]; + } + if (j < a[i]) { + f[i][j] = f[i - 1][j]; + } + } + } + cout << f[n][m] << endl; + return 0; +}