Skip to content

Instantly share code, notes, and snippets.

@HaiyangXu
Created January 5, 2015 14:50
Show Gist options
  • Save HaiyangXu/51257ec691a757ce5f51 to your computer and use it in GitHub Desktop.
Save HaiyangXu/51257ec691a757ce5f51 to your computer and use it in GitHub Desktop.
题目2 : Disk Storage
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef vector<int>::iterator IT;
vector<int> disks;
vector<bool> flag;
int M;
int maxdisk(int H,int R,int x,int counts){
if(H==0||counts>=disks.size())return 0;
int maxval=0;
IT it= upper_bound(disks.begin(), disks.end(), min(R,x));
for(IT i=disks.begin();i!=it;i++){
int loc=int(i-disks.begin());
if (flag[loc]) {
flag[loc]=false;
maxval=max(maxval,1+maxdisk(H-1, R+1, *i+M,counts+1));
flag[loc]=true;
}
}
return maxval;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int N,R,H;
cin>>N>>M>>H>>R;
int disk;
while(N--){
cin>>disk;
disks.push_back(disk);
}
flag.resize(disks.size());
fill(flag.begin(),flag.end(),true);
cout<<maxdisk(H,R,R,0);
}
@Insulator
Copy link

复杂度这么高,果然TLE= =。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment