比赛 |
20150423 |
评测结果 |
AAAAAAAAAAAAAA |
题目名称 |
守卫标志物 |
最终得分 |
100 |
用户昵称 |
Asm.Def |
运行时间 |
5.332 s |
代码语言 |
C++ |
内存使用 |
5.14 MiB |
提交时间 |
2015-04-23 10:22:04 |
显示代码纯文本
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <ctime>
- #include <cctype>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- //#define USEFREAD
- #ifdef USEFREAD
- #define InputLen 5000000
- char *ptr=(char *)malloc(InputLen);
- #define getc() (*(ptr++))
- #else
- #define getc() (getchar())
- #endif
- #define SetFile(x) (freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout))
- template<class T>inline void getd(T &x){
- int ch = getc();bool neg = false;
- while(!isdigit(ch) && ch != '-')ch = getc();
- if(ch == '-')ch = getc(), neg = true;
- x = ch - '0';
- while(isdigit(ch = getc()))
- x = x * 10 - '0' + ch;
- if(neg)x = -x;
- }
- /***********************************************************************/
- typedef long long LL;
- struct Cow{
- int str, h, w;
- }C[22];
-
- int N, H, Ans = -1, F[1100000], End;
- LL sumw, sumh;
- bool vis[1100000];
-
- void dfs(int i, LL w, LL h){//状态到了i,当前堆放了w,h
- int j, t;
- vis[i] = true;
- for(j = 0, t = 1;j < N;++j, t <<= 1)if(i & t){
- if(!vis[i ^ t])dfs(i ^ t, w - C[j].w, h - C[j].h);
- if(F[i ^ t] >= C[j].w)F[i] = max(F[i], min(C[j].str, F[i ^ t] - C[j].w));
- }
- if(h >= H)Ans = max(Ans, F[i]);
- }
-
- inline void init(){
- getd(N), getd(H);
- End = (1 << N) - 1;
- int i;
- Cow *it = C;
- for(i = 0;i < N;++i, ++it){
- getd(it->h), getd(it->w), getd(it->str);
- sumw += it->w, sumh += it->h;
- }
- memset(F, -1, sizeof(F));
- *F = 0x7fffffff;*vis = true;
- }
-
- int main(){
- #ifdef DEBUG
- freopen("test.txt", "r", stdin);
- #else
- SetFile(guardc);
- #endif
- #ifdef USEFREAD
- fread(ptr,1,InputLen,stdin);
- #endif
-
- init();
-
- dfs(End, sumw, sumh);
-
- if(~Ans)printf("%d\n", Ans);
- else puts("Mark is too tall");
-
- #ifdef DEBUG
- printf("\n%.3lf sec \n", (double)clock() / CLOCKS_PER_SEC);
- #endif
- return 0;
- }