From ab7d16e7b1c5e9c20d4af4e57558f770bfe2602b Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 25 May 2016 13:12:42 +0800 Subject: [PATCH] Create 1002_caesar_199.cpp From https://vijos.org/p/1002/solution --- VIJOS/1002_caesar_199.cpp | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 VIJOS/1002_caesar_199.cpp diff --git a/VIJOS/1002_caesar_199.cpp b/VIJOS/1002_caesar_199.cpp new file mode 100644 index 0000000..aac7d06 --- /dev/null +++ b/VIJOS/1002_caesar_199.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +using namespace std; + +int s, t, m, tot = 0, ans = 0; +long long l; +int vis[11000] = {0}; +int sto[110] = {0}; +int f[11000] = {0}; + +int main () +{ + //freopen ("in.txt", "r", stdin); + cin >> l >> s >> t >> m; + for (int i = 0; i < m; i++) cin >> sto[i]; + sort (sto, sto + m); + if (s == t) { + for (int i = 0; i < m; i++) { + if (!(sto[i]%s)) ans++; + } + cout << ans; + return 0; + } + int e; + if (sto[0] > 100) vis[tot = 100] = 1; + else vis[tot = sto[0]] = 1; + for (int i = 1; i < m; i++) { + if ((e = sto[i] - sto[i-1]) > 100) { vis[tot += 100] = 1;} + else { vis[tot += e] = 1;} + } + + for (int i = tot; i >= 0; i--) { + f[i] = 200; + for (int j = s; j <= t; j++) { + f[i] = min (f[i], f[i+j] + vis[i]); + } + } + cout << f[0]; + return 0; + }