Reputation: 61
Recently, i'd faced this error while solving a variation problem of knapsack. Can anyone please suggest some way to get rid of it.
const int n=105, w= 1000000005;
int val[n], ans[n][w];
int weight[n];
Error: size '4000000020' of array 'ans' exceeds maximum object size '2147483647'.
Upvotes: 0
Views: 1925
Reputation: 238351
Can anyone please suggest some way to get rid of it.
std::vector
.Upvotes: 0
Reputation: 3372
What your doing there is creating Tera Bytes worth of memory allocations. Usually you do those type of allocations in the heap (using vectors like std::vector<int> val(n);
and std::vector<std::vector<int>> ans(n, std::vector<int>(w));
). But still, are you sure you need that much of memory? After all your talking about as much as 105,000,000,525 integers.
Upvotes: 3