日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 1069 DP

發(fā)布時間:2023/12/16 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 1069 DP 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/****************************************************************************************************經典DP,LIS,最長上升子序列 ****************************************************************************************************/ #include <iostream> #include <iomanip> #include <functional> #include <algorithm> #include <complex> #include <cstdlib> #include <cstring> #include <fstream> #include <sstream> #include <utility> #include <bitset> #include <cctype> #include <cstdio> #include <limits> #include <memory> #include <string> #include <vector> #include <cmath> #include <ctime> #include <queue> #include <stack> #include <list> #include <map> #include <set> using namespace std;#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) ) #define CLR(x, k) memset((x), (k), sizeof(x)) #define CPY(t, s) memcpy((t), (s), sizeof(s)) #define SC(t, s) static_cast<t>(s) #define LEN(s) static_cast<int>( strlen((s)) ) #define SZ(s) static_cast<int>( (s).size() )typedef double LF; //typedef long long LL; //GNU C++ //typedef unsigned long long ULL; typedef __int64 LL; //Visual C++ 2010 typedef unsigned __int64 ULL;typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<double, double> PDD;typedef map<int, int>::iterator MI; typedef vector<int>::iterator VI; typedef list<int>::iterator LI; typedef set<int>::iterator SI;template <typename T> T sqa(const T &x) {return x * x; } template <typename T> T gcd(T a, T b) {if (!a || !b){return max(a, b);}T t;while (t = a % b){a = b;b = t;}return b; } template <typename T> T ext_gcd(T a, T b, T &x, T &y) {if (!b){x = 1;y = 0;return a;}T d = ext_gcd(b, a % b, x, y);T t = x; x = y;y = t - a / b * y;return d; } template <typename T> T invmod(T a, T p) {LL inv, y;ext_gcd(a, p, inv, y);inv < 0 ? inv += p : 0; return inv; }const int INF_INT = 0x3f3f3f3f; const LL INF_LL = 0x7fffffffffffffffLL; //15f const double oo = 10e9; const double eps = 10e-7; const double PI = acos(-1.0);#define ONLINE_JUDGEconst int MAXN = 504; const int loop[][3] = {{0, 1, 2}, {0, 2, 1}, {2, 1, 0}};int n, cube[MAXN][3]; int dp[MAXN]; struct Node {int x, y, z;int s;bool operator < (const Node &rhs) const{return x < rhs.x && y < rhs.y || x < rhs.y && y < rhs.x;}bool operator > (const Node &rhs) const{return x > rhs.x && y > rhs.y || x > rhs.y && y > rhs.x;} }node[MAXN], tmp[MAXN];bool inline nodeCmp(const Node &na, const Node &nb) {return na.s < nb.s; } void ace() {int cas = 1;int ncnt;while (cin >> n, n){for (int i = 0; i < n; ++i){for (int j = 0; j < 3; ++j){cin >> cube[i][j];}}for (int i = 0; i < n; ++i){for (int j = 0; j < 3; ++j) //因為立方體是無限的,但是x,y相同的立方體只可能出現一次{int k = i * 3 + j;node[k].x = cube[i][ loop[j][0] ];node[k].y = cube[i][ loop[j][1] ];node[k].z = cube[i][ loop[j][2] ];node[k].s = node[k].x * node[k].y;}}n *= 3;sort(node, node + n, nodeCmp); //對面積排序,盡量使小面積的在前面ncnt = 0;CLR(dp, 0);dp[0] = node[0].z; //dp數組記錄在當前第i個立方體放入后,以第i個立方體為底的高度for (int i = 1; i < n; ++i){int buf = 0;for (int j = 0; j < i; ++j) {if (node[i] > node[j] && buf < dp[j]) //顯然應該找之前最高的,因為只要保證node[i] > node[j]{ //那么i之前的狀態(tài)對于i來說是無關的 buf = dp[j];}}dp[i] = buf + node[i].z;}int res = 0;for (int i = 0; i < n; ++i){res = max(res, dp[i]);}printf("Case %d: maximum height = %d\n", cas++, res);}return ; } int main() { #ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin); #endiface();return 0; }

總結

以上是生活随笔為你收集整理的HDU 1069 DP的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。