4781번 - 사탕 가게
#include <iostream> #include <algorithm> #include <vector> #include <memory.h> using namespace std; int n,m; int dp[5001][10001]; int input[5001][2]; double d,temp; int main(){ while(1){ cin>>n; //n은 사탕 종류 수 m은 가진돈 if(!n)break; cin>>temp; m = (int)(temp*100+0.5); for(int i=0; i<=n; i++){ for(int j=0; j<=m; j++) { dp[i][j] = 0; input[i][j] = 0; } } for(int i=1; i<=n; i++){ cin>>input[i][0]; cin>>d; input[i][1] = (int)(d*100+0.5); } for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++){ //j는 현재 내가 가진돈 if(j<input[i][1]) //내가 가진돈이 사탕 살돈보다 적다면 사탕을 못삼. dp[i][j] = dp[i-1][j]; else dp[i][j] = max(dp[i-1][j],dp[i][j-input[i][1]]+input[i][0]); } } cout<<dp[n][m]<<endl; } return 0; } 간단한 문제인거 같은데 어디서 오류가 나는건지 모르겠습니다 도와주세요
int dp[5001][10001]; 은 약 200MB에 해당하므로, 메모리를 할당할 수 없어 에러가 납니다.
감사합니다~
댓글을 작성하려면 로그인해야 합니다.
simsimjae 6년 전