When I tried building my program today, I got a strange error in the C++ source code. None of my code is highlighted in red, so I'm pretty sure it's not a problem with my program. I don't remember messing around with anything other than what was written in inflate.cpp. Does anyone know what this is and how to fix it? Here are some screenshots of what happens.
EDIT: I realized this was actually a problem with my code, as I tried a different IDE and it gave the same error ._.
On IDEONE: http://ift.tt/2rS7qZn
Here is my code for inspection I guess. (I still don't know what's wrong with it)
/*
ID: ldorian1
LANG: C++11
TASK: inflate
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define INT_MAX 2147483647
using namespace std;
int totalTime;
int numCategories;
vector<pair<int,int>> categories; //categories[i].first is the number of points, categories[i].second is the time
int recur(int depth, int timeLeft) //returns most points that can be gotten with timeLeft time left while only using categories greater than or equal to depth
{
if(depth==numCategories-1)
{
return ((timeLeft/categories.at(depth).second)*categories.at(depth).first);
}
int currMax=0;
if(categories.at(depth).second>timeLeft) return 0;
F0R(i,timeLeft/categories.at(depth).second+1)
{
if(categories.at(depth).first*i+recur(depth+1,timeLeft-categories.at(depth).second*i)>currMax)
{
currMax=categories.at(depth).first*i+recur(depth+1,timeLeft-categories.at(depth).second*i);
}
}
return currMax;
}
bool compare(pair<int, int>i, pair<int, int>j)
{
return i.second < j.second;
}
int main()
{
//READING INPUT
//********************************************************************
ofstream fout("inflate.out");
ifstream fin("inflate.in");
fin >> totalTime >> numCategories;
F0R(i, numCategories)
{
vector<int,int> temp;
fin >> temp.first >> temp.second;
categories.push_back(temp);
}
sort(categories.begin(), categories.end(), compare);
//PRINTING OUTPUT
//********************************************************************
fout << recur(0,totalTime) << endl;
}
Aucun commentaire:
Enregistrer un commentaire