Submission #2241008
Source Code Expand
//2018年 3月 21日 水曜日 23:11:04 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////
int N; ll WD;
ll dp[110][310][110];
ll W[110], V[110];
void solve() {
cin >> N >> WD;
rep(i, 0, N) cin >> W[i] >> V[i];
ll wc = W[0];
rep(i, 0, N) {
rep(j, 0, 3 * N + 1) {
rep(k, 0, N + 1) {
dp[i][j][k] = -inf;
}
}
}
dp[0][0][0] = 0;
rep(i, 0, N) {
rep(j, 0, 3 * i + 1) {
rep(k, 0, i + 1) {
if(dp[i][j][k] == -inf) continue;
MAX(dp[i + 1][j + W[i] - wc][k + 1], dp[i][j][k] + V[i]);
MAX(dp[i + 1][j][k], dp[i][j][k]);
}
}
}
ll res = -inf;
rep(i, 0, 3 * N + 1) {
rep(l, 0, N + 1) {
if(wc * l + i <= WD) {
MAX(res, dp[N][i][l]);
}
}
}
cout << res << "\n";
}
int main() {
#ifndef LOCAL
ios::sync_with_stdio(false);
cin.tie(0);
#endif
cout << fixed;
cout.precision(20);
srand((unsigned int)time(NULL));
#ifdef LOCAL
//freopen("in.txt", "wt", stdout); //for tester
freopen("in.txt", "rt", stdin);
#endif
solve();
#ifdef LOCAL
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Simple Knapsack |
User |
omochana2 |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2612 Byte |
Status |
AC |
Exec Time |
10 ms |
Memory |
28928 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0, example1, example2, example3 |
All |
antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2 |
Case Name |
Status |
Exec Time |
Memory |
antigreedy0 |
AC |
10 ms |
28928 KB |
antigreedy1 |
AC |
10 ms |
28928 KB |
antigreedy2 |
AC |
10 ms |
28928 KB |
example0 |
AC |
1 ms |
384 KB |
example1 |
AC |
1 ms |
384 KB |
example2 |
AC |
1 ms |
384 KB |
example3 |
AC |
1 ms |
384 KB |
quarter0 |
AC |
10 ms |
28928 KB |
quarter1 |
AC |
10 ms |
28928 KB |
quarter2 |
AC |
10 ms |
28928 KB |
rand0 |
AC |
1 ms |
384 KB |
rand1 |
AC |
4 ms |
13568 KB |
rand2 |
AC |
3 ms |
6912 KB |
smallw0 |
AC |
10 ms |
28928 KB |
smallw1 |
AC |
10 ms |
28928 KB |
smallw2 |
AC |
10 ms |
28928 KB |