zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    Java 位运算(移位、位与、或、异或、非)
    解决Android Studio 2.2.3中添加.cpp .h文件在Project->Android无法显示,无法正常编译问题。
    [ACM] HDU 5083 Instruction (模拟)
    Vbox视图热键
    Android Drawable 与 LayerList综合汇总
    数学之路-python计算实战(14)-机器视觉-图像增强(直方图均衡化)
    HDU 2896 病毒侵袭 AC自己主动机题解
    对团队中“这是某某某的问题”引起的思考
    杭电 2201
    三层架构
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/10854004.html
Copyright © 2011-2022 走看看