SERCOI 近期设计了一种积木游戏。每一个游戏者有N块编号依次为1 ,2,…,N的长方体积木。

对于每块积木,它的三条不同的边分别称为”a边”、“b边”和”c边”。

游戏规则例如以下:

1. 从N块积木中选出若干块,并将它们分成M(l<=M<=N)堆,称为第1堆。第2
堆…。第M堆。

每堆至少有1块积木。而且第K堆中随意一块积木的编号要大于第K+1堆中随意一块积木的编号(2<=K<=M)。

2. 对于每一堆积木,游戏者要将它们垂直摞成一根柱子,并要求满足以下两个条件:

(a). 除最顶上的一块积木外。随意一块积木的上表面同且仅同还有一块积木的下表面接触,

而且要求以下的积木的上表面能包括上面的积木的下表面,

也就是说。要求以下的积木的上表面的两对边的长度分别大于等于上面的积木的两对边的长度。

(b). 对于随意两块上下表面相接触的积木,以下的积木的编号要小于上面的积木的编号。

最后。依据每人所摞成的M根柱子的高度之和来决出胜负。

请你编一程序,寻找一种摞积木的方案,使得你所摞成的M根柱子的高度之和最大。

思路:

顺序可略。多阶段决策

DP[col][used][top][face]代表在第 col 柱时。已经用了 used 个方块,第 col 上面是第 top 块的 face 面

1.当前木块放在第col上面。2.当前木块另起col。3.舍弃

#include <iostream>
#include <cstring>
using namespace std; struct Block{
int lens[3];
}; Block blocks[110];
int DP[110][110][110][3]; int M, N; int judge( int bellow, int f1, int up, int f2 ){ int bellow_a = blocks[bellow].lens[f1];
int bellow_b = blocks[bellow].lens[( f1 + 1 ) % 3];
int up_a = blocks[up].lens[f2];
int up_b = blocks[up].lens[( f2 + 1 ) % 3]; if( ( up_a <= bellow_a && up_b <= bellow_b ) ||
( up_a <= bellow_b && up_b <= bellow_a ) )
return blocks[up].lens[( f2 + 2 ) % 3]; return 0;
} int res_search( int col , int used, int top, int face ){ if( DP[col][used][top][face] )
return DP[col][used][top][face]; if( col == M && used == N )
return 0; if( col != M && used == N )
return -1; int res = 0; if( col ){
for( int f = 0; f <= 2; ++f ){ int ok = judge( top, face, used + 1, f ); if( ok )
res = max( res, res_search( col, used + 1, used + 1, f ) + ok ); }
} if( col < M ){
for( int f = 0; f <= 2; ++f ){
res = max( res, res_search( col + 1, used + 1, used + 1, f ) + blocks[used + 1].lens[( f + 2 ) % 3] );
}
} res = max( res, res_search( col, used + 1, top, face ) );
DP[col][used][top][face] = res; return res; } int main(){ while( cin >> N >> M ){ for( int i = 1; i <= N; ++i ){
cin >> blocks[i].lens[0] >> blocks[i].lens[1] >> blocks[i].lens[2];
} memset( DP, 0, sizeof( DP ) ); int res = res_search( 0, 0, 0, 0 ); cout << res << endl;
} return 0;
}

ecnu 1244的更多相关文章

  1. 【51Nod 1244】莫比乌斯函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...

  2. 51nod 1244 莫比乌斯函数之和

    题目链接:51nod 1244 莫比乌斯函数之和 题解参考syh学长的博客:http://www.cnblogs.com/AOQNRMGYXLMV/p/4932537.html %%% 关于这一类求积 ...

  3. DP URAL 1244 Gentlemen

    题目传送门 /* 题意:已知丢失若干卡片后剩余的总体积,并知道原来所有卡片的各自的体积,问丢失的卡片的id DP递推:首先从丢失的卡片的总体积考虑,dp[i] 代表体积为i的方案数,从dp[0] = ...

  4. ural 1244. Gentlemen

    1244. Gentlemen Time limit: 0.5 secondMemory limit: 64 MB Let's remember one old joke: Once a gentle ...

  5. 51nod 1244 莫比乌斯函数之和(杜教筛)

    [题目链接] http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...

  6. ECNU 3260 - 袋鼠妈妈找孩子

    题目链接:http://acm.ecnu.edu.cn/problem/3260/ Time limit per test: 1.5 seconds Time limit all tests: 10. ...

  7. ECNU 3263 - 丽娃河的狼人传说

    一定要纪念一下第一道在比赛中自己做出来的贪心. 题目链接:http://acm.ecnu.edu.cn/problem/3263/ Time limit per test: 1.0 seconds T ...

  8. 【51nod-1239&1244】欧拉函数之和&莫比乌斯函数之和 杜教筛

    题目链接: 1239:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239 1244:http://www.51nod. ...

  9. LightOJ 1244 - Tiles 猜递推+矩阵快速幂

    http://www.lightoj.com/volume_showproblem.php?problem=1244 题意:给出六种积木,不能旋转,翻转,问填充2XN的格子有几种方法.\(N < ...

随机推荐

  1. 优动漫PAINT中误删工具怎么办?

    最近收到一些小伙伴的提问,说我不小心把 XXX工具从面板上删掉了怎么办?本教程就来给大家分 享一下遇到这个问题时的三种解决方法,遇到同样问题的小伙伴们赶紧进来看一下哟! 优动漫PAINT下载:http ...

  2. [转载]vim常用命令总结

    内容出处https://www.jianshu.com/p/a8ab13cff1ea 如有侵权请告知 移动.跳转 h.j.k.l:分别对应左.下.上.右.按键盘分布,从左到右,逆时针. w:移动到下一 ...

  3. You Probably Don’t Need a Message Queue

    原文地址 I’m a minimalist, and I don’t like to complicate software too early and unnecessarily. And addi ...

  4. 紫书 习题8-6 UVa 1611 (构造法)

    这道题和例题8-1相当的像. 例题8-1https://blog.csdn.net/qq_34416123/article/details/80112017 一开始我还以为用归并的思想, 用交换把局部 ...

  5. Tarjan 割点割边【模板】

    #include <algorithm> #include <cstring> #include <cstdio> using namespace std; +); ...

  6. nginx php No input file specified 怎样处理?

    配置nginx支持php 出现了No input file specified ? 仅仅要改动下安装文件夹下的  nginx.conf下的 location ~ \.php$ {           ...

  7. codeforces 570 D Tree Requests

    题意:给出一棵树.每一个结点都有一个字母,有非常多次询问,每次询问.以结点v为根的子树中高度为h的后代是否可以经过调整变成一个回文串. 做法: 推断能否够构成一个回文串的话,仅仅须要知道是否有大于一个 ...

  8. HDOJ 2828 Lamp DLX反复覆盖

    DLX反复覆盖模版题: 每一个开关两个状态.但仅仅能选一个,建2m×n的矩阵跑DLX模版.. .. Lamp Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  9. hdoj 3376,2686 Matrix Again 【最小费用最大流】

    题目:hdoj 3376 Matrix Again 题意:给出一个m*n的矩阵,然后从左上角到右下角走两次,每次仅仅能向右或者向下,出了末尾点其它仅仅能走一次,不能交叉,每次走到一个格子拿走这个格子中 ...

  10. GridView中使用CheckBox

    asp.net中checkbox是向server提交时才干触发事件 把该控件的autopostback设置为true.才干响应事件  protected void Checkbox_CheckedCh ...