I couldn't find why my code failed. Can anyone please help me find my bug?
Thanks in advance.
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
using namespace std;
#define forn(i,n) for(int i = 0; i < (n); i++)
#define dforn(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
vector<bool> toc;
vector<pair<int,pair<int,int> > > vec;
set<vector<bool> > settoc;
int m;
int calc(int t, int n)
{
n = min(n,m);
if(settoc.find(toc)!=settoc.end())
return 0;
settoc.insert(toc);
if(t==0)
return 0;
int best0=-1,best1=-1,best2=-1,res=0;
forn(i,n)
if(toc[i]==false&&vec[i].second.second>0)
{
toc[i] = true;
t += vec[i].second.second-1;
n += vec[i].first;
if(n>m)
n = m;
res += vec[i].second.first;
}
forn(i,n)
{
if(toc[i]==false&&vec[i].first==0&&(best0==-1||vec[i].second.first>vec[best0].second.first))
best0 = i;
if(toc[i]==false&&vec[i].first==1&&(best1==-1||vec[i].second.first>vec[best1].second.first))
best1 = i;
if(toc[i]==false&&vec[i].first==2&&(best2==-1||vec[i].second.first>vec[best2].second.first))
best2 = i;
}
int respar = res;
int aux = res;
if(best0!=-1)
{
toc[best0]=true;
res = respar+vec[best0].second.first + calc(t-1,n);
toc[best0]=false;
}
aux = max(aux,res);
if(best1!=-1)
{
toc[best1]=true;
res = respar+vec[best1].second.first + calc(t-1,n+1);
toc[best1]=false;
}
aux = max(aux,res);
if(best2!=-1)
{
toc[best2]=true;
res = respar+vec[best2].second.first;
res += calc(t-1,n+2);
toc[best2]=false;
}
aux = max(aux,res);
return aux;
}
int freopen("C-small.out","w",stdout);
int casos;
cin >> casos;
forn(casito,casos)
{
int n;
cin >> n;
vec.resize(n);
forn(i,n)
cin >> vec[i].first >> vec[i].second.first >>
vec[i].second.second;
cin >> m;
vec.resize(n+m);
for(int i=n;i<n+m;i++)
cin >> vec[i].first >> vec[i].second.first >>
vec[i].second.second;
int t = 1;
m = n+m;
toc.clear();
forn(i,m)
toc.push_back(false);
int res = 0;
settoc.clear();
cout << "Case #" << casito+1 << ": " << calc(t,n)<< endl;
}
} main()
{
freopen("C-small.in","r",stdin);
freopen("C-small.out","w",stdout);
int casos;
cin >> casos;
forn(casito,casos)
{
int n;
cin >> n;
vec.resize(n);
forn(i,n)
cin >> vec[i].first >> vec[i].second.first >>
vec[i].second.second;
cin >> m;
vec.resize(n+m);
for(int i=n;i<n+m;i++)
cin >> vec[i].first >> vec[i].second.first >>
vec[i].second.second;
int t = 1;
m = n+m;
toc.clear();
forn(i,m)
toc.push_back(false);
int res = 0;
settoc.clear();
cout << "Case #" << casito+1 << ": " << calc(t,n)<< endl;
}
}
--
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.