-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
9,175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <queue> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <algorithm> | ||
#include <functional> | ||
#include <stack> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
const int INF = 0x3F3F3F3F, MAX_VALUE = 0x7FFFFFFF, MIN_VALUE = 0x80000000, MOD = 1E9 + 7; | ||
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | ||
#define debug puts("pigtoria bling bling ⚡️⚡️"); | ||
#define FOR(i, a, b) for (int i = a; i < b; i++) | ||
#define FORD(i, a, b) for (int i = a; i >= b; i--) | ||
#define pii pair<int, int> | ||
#define LL long long | ||
#define LD long double | ||
#define PB push_back | ||
#define EB emplace_back | ||
#define MP make_pair | ||
#define FI first | ||
#define SE second | ||
|
||
class Solution { | ||
public: | ||
int CompletePack(int n, int v, vector<pii > data) { | ||
vector<int> dp(v + 1); | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j <= v; j++) { | ||
if(j>=data[i].first){ | ||
dp[j]=max(dp[j],dp[j-data[i].first]+data[i].second); | ||
} | ||
} | ||
} | ||
return dp[v]; | ||
} | ||
}; | ||
|
||
int main() { | ||
int n, v; | ||
cin >> n >> v; | ||
vector <pii> data; | ||
for (int i = 0; i < n; i++) { | ||
int vi, wi; | ||
cin >> vi >> wi; | ||
data.EB(make_pair(vi, wi)); | ||
} | ||
Solution INSTANCE; | ||
int ans = INSTANCE.CompletePack(n, v, data); | ||
cout << ans << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <queue> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <algorithm> | ||
#include <functional> | ||
#include <stack> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
const int INF = 0x3F3F3F3F, MAX_VALUE = 0x7FFFFFFF, MIN_VALUE = 0x80000000, MOD = 1E9 + 7; | ||
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | ||
#define debug puts("pigtoria bling bling ⚡️⚡️"); | ||
#define FOR(i, a, b) for (int i = a; i < b; i++) | ||
#define FORD(i, a, b) for (int i = a; i >= b; i--) | ||
#define pii pair<int, int> | ||
#define LL long long | ||
#define LD long double | ||
#define PB push_back | ||
#define EB emplace_back | ||
#define MP make_pair | ||
#define FI first | ||
#define SE second | ||
|
||
// 多重背包 | ||
class Solution { | ||
public: | ||
int MultiPack(int n, int v, vector<vector<int>> data) { | ||
vector<int> dp(v + 1); | ||
for (int i = 0; i < data.size(); i++) { | ||
int vi = data[i][0], wi = data[i][1], si = data[i][2]; | ||
MultiplePack(vi, wi, si, dp, v); | ||
} | ||
return dp[v]; | ||
} | ||
|
||
int MultiplePack(int vi, int wi, int si, vector<int> &dp, int V) { | ||
if (vi * si >= V) { | ||
CompletePack(vi, wi, dp, V); | ||
return dp[V]; | ||
} | ||
int s = 1; | ||
while (s < si) {//条件:amount-s>0 | ||
ZeroOnePack(s * vi, s * wi, dp, V); | ||
si -= s; | ||
s *= 2; | ||
} | ||
ZeroOnePack(si * vi, si * wi, dp, V); | ||
return dp[V]; | ||
} | ||
|
||
// 抽象化: 抽取01背包问题为处理一件物品 | ||
int ZeroOnePack(int vi, int wi, vector<int> &dp, int V) { | ||
for (int j = V; j >= vi; j--) { | ||
dp[j] = max(dp[j], dp[j - vi] + wi); | ||
} | ||
return dp[V];// 返回的是容量为V时候,处理一件物品获取的最大值 | ||
} | ||
|
||
// 抽象化: 对一种物品的处理过程 | ||
int CompletePack(int vi, int wi, vector<int> &dp, int V) { | ||
for (int j = 0; j <= V; j++) { | ||
if (j >= vi) dp[j] = max(dp[j], dp[j - vi] + wi); | ||
} | ||
return dp[V]; | ||
} | ||
}; | ||
|
||
int main() { | ||
int n, v; | ||
cin >> n >> v; | ||
vector <vector<int>> data; | ||
int vi, wi, si; | ||
for (int i = 0; i < n; ++i) { | ||
cin >> vi >> wi >> si; | ||
data.EB(vector < int > {vi, wi, si}); | ||
} | ||
Solution INSTANCE; | ||
int ans = INSTANCE.MultiPack(n, v, data); | ||
cout << ans << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <queue> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <algorithm> | ||
#include <functional> | ||
#include <stack> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
const int INF = 0x3F3F3F3F, MAX_VALUE = 0x7FFFFFFF, MIN_VALUE = 0x80000000, MOD = 1E9 + 7; | ||
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | ||
#define debug puts("pigtoria bling bling ⚡️⚡️"); | ||
#define FOR(i, a, b) for (int i = a; i < b; i++) | ||
#define FORD(i, a, b) for (int i = a; i >= b; i--) | ||
#define pii pair<int, int> | ||
#define LL long long | ||
#define LD long double | ||
#define PB push_back | ||
#define EB emplace_back | ||
#define MP make_pair | ||
#define FI first | ||
#define SE second | ||
|
||
class Solution { | ||
public: | ||
int GroupPacK(int N, int V, vector<vector<pii>> &groups) { | ||
vector<int> dp(V + 1); | ||
for (int i = 0; i < N; i++) { | ||
for (int v = V; v >= 0; v--) { | ||
for (int j = 0; j < groups[i].size(); j++) { | ||
if (v >= groups[i][j].first)dp[v] = max(dp[v], dp[v - groups[i][j].first] + groups[i][j].second); | ||
} | ||
} | ||
} | ||
return dp[V]; | ||
} | ||
}; | ||
|
||
|
||
// 分组背包 | ||
int main() { | ||
int N, V; | ||
cin >> N >> V; | ||
int si, vij, wij; | ||
vector <vector<pii>> groups; | ||
for (int i = 0; i < N; i++) { | ||
cin >> si; | ||
vector <pii> group; | ||
for (int i = 0; i < si; ++i) { | ||
cin >> vij >> wij; | ||
group.EB(make_pair(vij, wij)); | ||
} | ||
groups.EB(group); | ||
group.clear(); | ||
} | ||
Solution INSTANCE; | ||
int ans = INSTANCE.GroupPacK(N, V, groups); | ||
cout << ans << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <queue> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <algorithm> | ||
#include <functional> | ||
#include <stack> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
const int INF = 0x3F3F3F3F, MAX_VALUE = 0x7FFFFFFF, MIN_VALUE = 0x80000000, MOD = 1E9 + 7; | ||
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | ||
#define debug puts("pigtoria bling bling ⚡️⚡️"); | ||
#define FOR(i, a, b) for (int i = a; i < b; i++) | ||
#define FORD(i, a, b) for (int i = a; i >= b; i--) | ||
#define pii pair<int, int> | ||
#define LL long long | ||
#define LD long double | ||
#define PB push_back | ||
#define EB emplace_back | ||
#define MP make_pair | ||
#define FI first | ||
#define SE second | ||
|
||
// dp(i,j)=dp(i,k)+sum(k+1,m)+dp(m+1,j) | ||
class Solution { | ||
public: | ||
int mergeStone(vector<int> arr) { | ||
|
||
} | ||
}; | ||
|
||
int main() { | ||
int N; | ||
vector<int> arr; | ||
int val; | ||
while (N--) { | ||
cin >> val; | ||
arr.EB(val); | ||
} | ||
Solution INSTANCE; | ||
int ans = INSTANCE.mergeStone(arr); | ||
cout << ans << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <queue> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <algorithm> | ||
#include <functional> | ||
#include <stack> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
const int INF = 0x3F3F3F3F, MAX_VALUE = 0x7FFFFFFF, MIN_VALUE = 0x80000000, MOD = 1E9 + 7; | ||
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | ||
#define debug puts("pigtoria bling bling ⚡️⚡️"); | ||
#define FOR(i, a, b) for (int i = a; i < b; i++) | ||
#define FORD(i, a, b) for (int i = a; i >= b; i--) | ||
#define pii pair<int, int> | ||
#define LL long long | ||
#define LD long double | ||
#define PB push_back | ||
#define EB emplace_back | ||
#define MP make_pair | ||
#define FI first | ||
#define SE second |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <queue> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <algorithm> | ||
#include <functional> | ||
#include <stack> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
const int INF = 0x3F3F3F3F, MAX_VALUE = 0x7FFFFFFF, MIN_VALUE = 0x80000000, MOD = 1E9 + 7; | ||
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | ||
#define debug puts("pigtoria bling bling ⚡️⚡️"); | ||
#define FOR(i, a, b) for (int i = a; i < b; i++) | ||
#define FORD(i, a, b) for (int i = a; i >= b; i--) | ||
#define pii pair<int, int> | ||
#define LL long long | ||
#define LD long double | ||
#define PB push_back | ||
#define EB emplace_back | ||
#define MP make_pair | ||
#define FI first | ||
#define SE second |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <queue> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <algorithm> | ||
#include <functional> | ||
#include <stack> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
const int INF = 0x3F3F3F3F, MAX_VALUE = 0x7FFFFFFF, MIN_VALUE = 0x80000000, MOD = 1E9 + 7; | ||
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | ||
#define debug puts("pigtoria bling bling ⚡️⚡️"); | ||
#define FOR(i, a, b) for (int i = a; i < b; i++) | ||
#define FORD(i, a, b) for (int i = a; i >= b; i--) | ||
#define pii pair<int, int> | ||
#define LL long long | ||
#define LD long double | ||
#define PB push_back | ||
#define EB emplace_back | ||
#define MP make_pair | ||
#define FI first | ||
#define SE second |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <queue> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <algorithm> | ||
#include <functional> | ||
#include <stack> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
const int INF = 0x3F3F3F3F, MAX_VALUE = 0x7FFFFFFF, MIN_VALUE = 0x80000000, MOD = 1E9 + 7; | ||
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | ||
#define debug puts("pigtoria bling bling ⚡️⚡️"); | ||
#define FOR(i, a, b) for (int i = a; i < b; i++) | ||
#define FORD(i, a, b) for (int i = a; i >= b; i--) | ||
#define pii pair<int, int> | ||
#define LL long long | ||
#define LD long double | ||
#define PB push_back | ||
#define EB emplace_back | ||
#define MP make_pair | ||
#define FI first | ||
#define SE second | ||
|
||
// tag: 线性dp | ||
int main() { | ||
fastio | ||
int N; | ||
cin >> N; | ||
vector<int> arr; | ||
int val; | ||
for (int i = 0; i < N; i++) { | ||
cin >> val; | ||
arr.EB(val); | ||
} | ||
vector<int> dp(N, 1); | ||
|
||
int ans = MIN_VALUE; | ||
for (int i = 0; i < N; ++i) { | ||
for (int j = 0; j < i; ++j) { | ||
if (arr[i] > arr[j]) { | ||
dp[i] = max(dp[i], dp[j] + 1); | ||
} | ||
} | ||
ans = max(ans, dp[i]); | ||
} | ||
cout << ans << endl; | ||
return 0; | ||
} |
Oops, something went wrong.