-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1-rivkms #5
1-rivkms #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
|
||
int main(){ | ||
int n, k; | ||
cin >> n >> k; | ||
vector<pair<int, int>> wv(n+1, pair<int, int>(0,0)); | ||
vector<vector<int>> value (n+1, vector<int>(k+1, 0)); | ||
for(int i = 1; i<=n; i++){ | ||
cin >> wv[i].first >> wv[i].second; | ||
} | ||
|
||
for(int i = 1; i<=n; i++){ | ||
for(int j = 1; j<=k;j++){ | ||
if(wv[i].first > j ){ | ||
value[i][j] = value[i-1][j]; | ||
} | ||
else{ | ||
value[i][j] = max(value[i-1][j], value[i-1][j-wv[i].first]+wv[i].second); | ||
} | ||
Comment on lines
+8
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ κ° c++μμ μ½λꡬνμ΄ μ΅μνμ§ μμ μ¬μ€λ³΄μλ©΄ μμ λΈλμμ μ
λ ₯κ°μ λ°κ³ μλ forλ¬Έμμ κ΄κ³μμ μ΄μ©νμ¬ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λ΅ valueκ° DP Tableμ΄λΌκ³ 보μλ©΄ λκ³ DP Tableμ κ΄κ³μμ μ΄μ©ν΄μ μ±μλκ°λ€κ³ μκ°νμλ©΄ λ©λλ€ π |
||
|
||
} | ||
} | ||
cout << value[n][k]; | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ·Έλ¦Όμ΄ μμΌλκΉ μκ³ λ¦¬μ¦ μ΄ν΄κ° νμ€ν μλλ€μ. λλΆμ μ’μ μμ΄λμ΄ νλ μ»κ³ κ°λλ€!