Created
January 5, 2015 14:50
-
-
Save HaiyangXu/51257ec691a757ce5f51 to your computer and use it in GitHub Desktop.
题目2 : Disk Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
复杂度这么高,果然TLE= =。。