Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions ArrayDescription.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
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<vector<int>> dp(n, vector<int>(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;
}
54 changes: 54 additions & 0 deletions BookShop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
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<n; i++){
cin >> prices[i];
}

for(int i=0; i<n; i++){
cin >> pages[i];
}

vector<vector<int>> dp(n+1, vector<int>(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;
}

}
49 changes: 49 additions & 0 deletions CoinCombination1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
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<int> c, int n)
{
int mod = 1e9 + 7;
vector<int> 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<int> c(n);
for (int &v : c)
{
cin >> v;
}

BottomUp(target, c, n);

return 0;
}
40 changes: 40 additions & 0 deletions CoinCombination2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
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<int> c(n);
for (int &v : c)
cin >> v;

int mod = 1e9+7;
vector<vector<int>> dp(n+1, vector<int>(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;
}