diff --git a/ArrayDescription.cpp b/ArrayDescription.cpp new file mode 100644 index 0000000..cdca738 --- /dev/null +++ b/ArrayDescription.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +#define ll long long int + +#define OJ \ + freopen("input.txt", "r", stdin); \ + freopen("output.txt", "w", stdout); +#define FIO \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL); + +int main() +{ + //OJ; + int mod = 1e9 + 7; + int n, m; + cin >> n >> m; + vector> dp(n, vector(m + 1, 0)); + int x0; + cin >> x0; + if (x0 == 0) + { + fill(dp[0].begin(), dp[0].end(), 1); + } + else + { + dp[0][x0] = 1; + } + for (int i = 1; i < n; i++) + { + int x; + cin >> x; + if (x == 0) + { + for (int j = 1; j <= m; j++) + { + for (int k : {j - 1, j, j + 1}) + { + if (k >= 1 && k <= m) + { + (dp[i][j] += dp[i - 1][k]) %= mod; + } + } + } + } + else + { + for (int k : {x - 1, x, x + 1}) + { + if (k >= 1 && k <= m) + { + (dp[i][x] += dp[i - 1][k]) %= mod; + } + } + } + } + + + int ans = 0; + for(int i=1; i<=m; i++){ + (ans+= dp[n-1][i])%=mod; + } + + cout << ans << endl; +} \ No newline at end of file diff --git a/BookShop.cpp b/BookShop.cpp new file mode 100644 index 0000000..2d659ec --- /dev/null +++ b/BookShop.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +#define ll long long int + +#define OJ \ + freopen("input.txt", "r", stdin); \ + freopen("output.txt", "w", stdout); +#define FIO \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL); + +int main() +{ + OJ; + int n, maxBooks; + cin >> n >> maxBooks; + int* prices = new int[n]; + int* pages = new int[n]; + + for(int i=0; i> prices[i]; + } + + for(int i=0; i> pages[i]; + } + + vector> dp(n+1, vector(maxBooks+1, 0)); + for(int i=1; i<=n; i++){ + for(int j= 0; j <=maxBooks; j++){ + dp[i][j] = dp[i-1][j]; + int left = j-prices[i-1]; + if(left>=0){ + dp[i][j] = max(dp[i][j], dp[i-1][left]+pages[i-1]); + } + + } + } + + for(int i=0; i<=n; i++){ + for(int j=0; j<=maxBooks; j++){ + cout << dp[i][j] << " "; + } + cout << endl; + } + +} \ No newline at end of file diff --git a/CoinCombination1.cpp b/CoinCombination1.cpp new file mode 100644 index 0000000..7204a86 --- /dev/null +++ b/CoinCombination1.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +using namespace std; + +#define ll long long int + +#define OJ \ + freopen("input.txt", "r", stdin); \ + freopen("output.txt", "w", stdout); +#define FIO \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL); + +void BottomUp(int target, vector c, int n) +{ + int mod = 1e9 + 7; + vector dp(target + 1, 0); + dp[0] = 1; + for (int i = 1; i <= target; i++) + { + for (int j = 0; j < n; j++) + { + if (i - c[j] >= 0) + { + (dp[i] += dp[i - c[j]]) %= mod; + } + } + } + cout << dp[target] << endl; +} + +int main() +{ + //OJ; + int n, target; + cin >> n >> target; + vector c(n); + for (int &v : c) + { + cin >> v; + } + + BottomUp(target, c, n); + + return 0; +} \ No newline at end of file diff --git a/CoinCombination2.cpp b/CoinCombination2.cpp new file mode 100644 index 0000000..d986446 --- /dev/null +++ b/CoinCombination2.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +using namespace std; + +#define ll long long int + +#define OJ \ + freopen("input.txt", "r", stdin); \ + freopen("output.txt", "w", stdout); +#define FIO \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL); + +int main() +{ + //OJ; + int n, target; + cin >> n >> target; + vector c(n); + for (int &v : c) + cin >> v; + + int mod = 1e9+7; + vector> dp(n+1, vector(target+1, 0)); + dp[0][0] = 1; + for(int i=1; i<=n; i++){ + for(int j=0; j<=target; j++){ + dp[i][j] = dp[i-1][j]; + if(j-c[i-1]>=0){ + (dp[i][j]+=dp[i][j-c[i-1]])%=mod; + } + } + } + + cout << dp[n][target] << endl; + return 0; +} \ No newline at end of file