uva-103-dp----has error
Posted shuiyonglewodezzzzz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva-103-dp----has error相关的知识,希望对你有一定的参考价值。
题意:矩阵嵌套,DAG图DP
下面的代码在hdu过不了,voj能过.详见http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=38519&messageid=1&deep=0
#include <string> #include<iostream> #include<map> #include<memory.h> #include<vector> #include<algorithm> #include<queue> #include<vector> #include<stack> #include<math.h> #include<iomanip> #include<bitset> #include"math.h" namespace cc { using std::cout; using std::endl; using std::cin; using std::map; using std::vector; using std::string; using std::sort; using std::priority_queue; using std::greater; using std::vector; using std::swap; using std::stack; using std::queue; using std::bitset; constexpr int N = 64; constexpr int D = 11; int k; int n; class Node { public: int d[16] = { 0 }; int index; const bool operator < (const Node& n2) const { for (int i = 0;i < k;i++) { if (this->d[i] == n2.d[i]) continue; if (this->d[i] > n2.d[i]) return false; else return true; } return false; } }; Node nodes[N]; int m[N][N]; int dp[N]; int path[N]; void build() { for (int i = 0;i < n;i++) { for (int j = i + 1;j < n;j++) { int ok = 1; for (int t = 0;t < k;t++) { if (nodes[i].d[t] >= nodes[j].d[t]) { ok = 0; break; } } if (ok) { m[i][j] = 1; } } } } int first = 1; void print(int maxIndex,int max) { if (max == 0) { return; } print(path[maxIndex],max-1); if (first) { cout << nodes[path[maxIndex]].index; first = 0; } else { cout << " " << nodes[path[maxIndex]].index; } } void solve() { while (cin>>n>>k) { if (n == 0 && k == 0) return; for (int i=0;i<n;i++) { Node in; in.index = i + 1; for (int j=0;j<k;j++) { cin >> in.d[j]; } sort(in.d,in.d+k); nodes[i] = in; } sort(nodes,nodes+n); //bubbleSort(); memset(m, 0, sizeof(m)); build(); memset(dp,0,sizeof(dp)); memset(path,0,sizeof(path)); int max = -1; int maxIndex = -1; first = 1; for (int i=0;i<n;i++) { int curMax = 1; for (int j=0;j<i;j++) { if (m[j][i] == 0) continue; if (1 + dp[j] > curMax) { path[i]=j; curMax = 1 + dp[j]; } } dp[i] = curMax; if (curMax > max) { max = curMax; maxIndex = i; } } cout << max << endl; //cout print(maxIndex, max-1); if(first) cout<<nodes[maxIndex].index << endl; else { cout<<" " << nodes[maxIndex].index << endl; } } } }; int main() { #ifndef ONLINE_JUDGE freopen("d://1.text", "r", stdin); //freopen("d://1.out", "w", stdout); #endif // !ONLINE_JUDGE cc::solve(); return 0; }
以上是关于uva-103-dp----has error的主要内容,如果未能解决你的问题,请参考以下文章
SignTool Error: An error occurred while attempting/Error information: “SignerTimeStamp() failed.“(代码
为啥这段代码会抛出 java.lang.***Error [重复]
SERVER_ERROR:[代码] 1675030 [消息]:执行查询时出错
error.networkResponse 为空时 Android Volley 中的 Http 状态代码
IDEA运行Spark代码异常 -> Error:scalac: IO error while decoding Demo2.scala with UTF-8