``````A:BCDH
``````

B：

4

A:BCD

B:ACD

C:ABD

D:ABC

4

22 3

7 0 1

110

4 2

1 2 1

4 2 2

2 3 3

2

1 3

5

1个回答

Professor. 同学 你也够呛

qq_27279883 不能

C编写的分支限界法解01背包问题嵌入窗口界面代码问题

#include <**iostream**> #include <**fstream**> #include <**algorithm**> #include <**functional**> #include <**queue**> using namespace std; class BoardNode{ public: int *x;//x[1:n]记录电路板排列 int n; int t;//x[1:t]是当前节点所相应的部分排列 int maxL;//x[1:s]的最大长度 BoardNode(){}; BoardNode(BoardNode const &source){ n = source.n; t = source.t; maxL = source.maxL; x = new int[n + 1]; for (int i = 0; i <= n; ++i) x[i] = source.x[i]; } bool Comput(int i,int m,int **B);//计算本块所形成的排列maxL bool operator < (const BoardNode &A)const{ if (this->t > A.t) return true; else if(this->t == A.t){ return this->maxL < A.maxL ? true : false; } else return false; } }; bool BoardNode::Comput(int i,int m,int **B){ ++this->t; swap(x[t],x[i]); int *low = new int[m + 1]; int *high = new int[m + 1]; for (int j = 0; j <= m; ++j){ low[j] = m; high[j] = 0; } for (j = 1; j <= t; ++j){ for (int k = 1; k <= m; ++k){ if (B[x[j]][k]){ if (j < low[k]) low[k] = j; if (j > high[k]) high[k] = j; } } } maxL = 0; for (j = 1; j <=t ;++j){ if (maxL < high[j] - low[j]) maxL = high[j] - low[j]; } delete low; delete high; return true; } ////////////////////////////////// class minBorad{ private: int **B;//描述矩阵 int n;//n块电路板 int m;//m个连接块 int *bestx;//bestx[1:n]最优排列 int bestMaxL;//最优最大长度 BoardNode E; priority_queue<BoardNode> Heap; void BBArrangement(); void cmpBest(BoardNode &newBoardNode); public: minBorad(){}; minBorad(int **B, int n, int m){ this->B = B; this->n = n; this->m = m; bestx = new int[n + 1]; bestMaxL = INT_MAX; E.x = new int[n + 1]; E.maxL = 0; E.n = n; E.t = 0; for (int i = 0; i <= n; ++i) { E.x[i] = i; } BBArrangement(); } int getBestMaxL(){return this->bestMaxL;} int *getBestx(){return this->bestx;} }; void minBorad::cmpBest(BoardNode &newBoardNode){ if (newBoardNode.maxL <= this->bestMaxL) { this->bestMaxL = newBoardNode.maxL; cout<<"当前最优："<<newBoardNode.maxL<<endl; for (int i = 0; i <= n; ++i) { this->bestx[i] = newBoardNode.x[i]; cout<<bestx[i]<<" "; } cout<<endl; } } void minBorad::BBArrangement(){ Heap.push(E); while(!Heap.empty()){ BoardNode nowNode(Heap.top()); Heap.pop(); // cout<<"弹出节点 "<<nowNode.t<<endl; // for (int z = 0; z <= n; ++z) // { // cout<<nowNode.x[z]<<" "; // } // cout<<endl; for (int i = nowNode.t + 1; i <= n; ++i) { BoardNode newBoardNode(nowNode); newBoardNode.Comput(i,m,B); if (newBoardNode.maxL < bestMaxL)//如果当前最大长度小于最优长度则搜索子树 { if (newBoardNode.t == n) { cmpBest(newBoardNode); } else{ Heap.push(newBoardNode); // cout<<"加入节点 "<<newBoardNode.t<<endl; // for (int z = 0; z <= n; ++z) // { // cout<<newBoardNode.x[z]<<" "; // } // cout<<endl; } } } } }; int main(){ ifstream in("input.txt"); ofstream out("output.txt"); //#define in cin //#define out cout int cases; in>>cases; for(int Case = 1; Case <= cases; ++Case){ int n,m; in>>n>>m; int **B = new int *[n + 1]; int i,j; for (i = 1; i <= n; ++i) { B[i] = new int [m]; } for (i = 1; i <= n; ++i) { for (j = 1; j <= m; ++j) { in>>B[i][j]; } } minBorad cmpMinBorad(B,n,m); out<<"Case #"<<Case<<": "<<cmpMinBorad.getBestMaxL()<<endl; for (j = 1; j <= n; ++j) { out<<(cmpMinBorad.getBestx())[j]<<" "; } out<<endl; } return 0; } input问文本输入 8 5 11111 01010 01110 10110 10100 11010 00001 01001 output输出的结果不对为什么啊？？？还有算法复杂度是多少啊？怎么算的

#include <iostream> #include <queue> #include<stdio.h> #include<stdlib.h> using namespace std;![![图片说明](https://img-ask.csdn.net/upload/201501/10/1420849445_117270.png) //定义一个队列 void NQueens(); //定义该皇后可以存在的位置 bool CanPos(int *pos, int level, int i); //得到N在队列中的位置 int * GetNQueensPos(int n); int main() { NQueens(); } //该方法用于获取当前N皇后应该在哪个合适的位置 int * GetNQueensPos(int n) { //通过创建一个数组用于存放N皇后的大小 int *pos = new int[n]; //设置当前的行数默认为O int level = 0; //使用队列式保存N皇后在哪个行数和N皇后在行数的哪个具体位置 queue<int*> *QPos = new queue<int*>(); queue<int> *QLevel = new queue<int>(); while (true) { //N皇后的个数超过行数，则退出该循环 if (level == n) { break; } //通过for循环判断N皇后在哪行哪列合适 for (int i = 1; i <=n; ++i) { //N皇后在某个位置是否合适的结果判断出具体可以放的合适的位置 if (CanPos(pos, level, i)) { //将第i个合适的皇后放置在指定的行数上 pos[level] = i; //将合适的位置推进队列中 QPos->push(pos); //将当前合适的行号推进队列中 QLevel->push(level + 1); break; } } //将当前的位置向前走一位 pos = QPos->front(); QPos->pop(); //将当前的行号向前走一位 level = QLevel->front(); QLevel->pop(); } //返回该皇后合适的位置 return pos; } //该方法可以实现得到N皇后可以放置的位置是否合适 bool CanPos(int *pos, int level, int i) { //通过一个for循环判断N皇后是否不符合要求，符合则返回true，反之亦然 for (int j = 0; j < level; ++j) { if (abs(pos[j] - i) == abs(j - level) || (pos[j] == i)) { return false; } } return true; } //用于main方法调用并返回找到的合适的结果 void NQueens() { int n; cout<<"请输入N皇后个数n:"<<endl; cin>>n; //通过循环的方式将符合条件的皇后位置输出来 int *pos = GetNQueensPos(n); cout<<"N个皇后放置的情况如下:"<<endl; for (int i = 0; i < n; ++i) { cout << pos[i] << " "; } cout << endl; } 图片说明](https://img-ask.csdn.net/upload/201501/10/1420849365_69472.png) 详细错误是 ****请输入N皇后个数n: 6 Process returned -1073741819 (0xC0000005) execution time : 5.289 s Press any key to continue.****

C语言编程问题，不懂求解答

Graph地运用的旅行商的一个问题，怎么采用C语言的程序的编写的设计的代码的方式有效地实现的

Problem Description Long before the days of international trade treaties, a salesman would need to pay taxes at every border crossed. So your task is to find the minimum number of borders that need to be crossed when traveling between two countries. We model the surface of Earth as a set of polygons in three dimensions forming a closed convex 3D shape, where each polygon corresponds to one country. You are not allowed to cross at points where more than two countries meet. Input Each test case consists of a line containing c, the number of countries (4 ≤ c ≤ 6000), followed by c lines containing the integers n x1 y1 z1 … xn yn zn, describing (in order) the n corners of a closed polygon (3 ≤ n ≤ 20). Then follows a line with one integer m (0 < m ≤ 50), and then m lines with queries ca cb, where ca and cb are country numbers (starting with 1). No point will be on the line between two connected points, and -106 ≤ x, y, z ≤ 106 for all points. No two non-adjacent edges of a country share a common point. The input is terminated by a case where c = 0, which should not be processed. Output For each query, output the number of borders you must cross to go from ca to cb. Sample Input 6 4 0 0 0 0 0 1 0 1 1 0 1 0 4 1 0 0 1 0 1 1 1 1 1 1 0 4 0 0 0 1 0 0 1 0 1 0 0 1 4 0 1 0 1 1 0 1 1 1 0 1 1 4 0 0 0 0 1 0 1 1 0 1 0 0 4 0 0 1 0 1 1 1 1 1 1 0 1 2 1 2 1 3 0 Sample Output 2 1

Cliff Climbing

Problem Description At 17:00, special agent Jack starts to escape from the enemy camp. There is a cliff in between the camp and the nearest safety zone. Jack has to climb the almost vertical cliff by stepping his feet on the blocks that cover the cliff. The cliff has slippery blocks where Jack has to spend time to take each step. He also has to bypass some blocks that are too loose to support his weight. Your mission is to write a program that calculates the minimum time to complete climbing. Figure D-1 shows an example of cliff data that you will receive. The cliff is covered with square blocks. Jack starts cliff climbing from the ground under the cliff, by stepping his left or right foot on one of the blocks marked with 'S' at the bottom row. The numbers on the blocks are the "slippery levels". It takes t time units for him to safely put his foot on a block marked with t, where 1 ≤ t ≤ 9. He cannot put his feet on blocks marked with 'X'. He completes the climbing when he puts either of his feet on one of the blocks marked with 'T' at the top row. Figure D-1: Example of Cliff Data Jack's movement must meet the following constraints. After putting his left (or right) foot on a block, he can only move his right (or left, respectively) foot. His left foot position (lx, ly) and his right foot position (rx, ry) should satisfy lx < rx and | lx - rx | + | ly - ry | ≤ 3. This implies that, given a position of his left foot in Figure D-2 (a), he has to place his right foot on one of the nine blocks marked with blue color. Similarly, given a position of his right foot in Figure D-2 (b), he has to place his left foot on one of the nine blocks marked with blue color. Figure D-2: Possible Placements of Feet Input The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows: w h s(1,1) ... s(1,w) s(2,1) ... s(2,w) ... s(h,1) ... s(h,w) The integers w and h are the width and the height of the matrix data of the cliff. You may assume 2 ≤ w ≤ 30 and 5 ≤ h ≤ 60. Each of the following h lines consists of w characters delimited by a space. The character s(y, x) represents the state of the block at position (x, y) as follows: * 'S': Jack can start cliff climbing from this block. * 'T': Jack finishes climbing when he reaches this block. * 'X': Jack cannot put his feet on this block. * '1' - '9' (= t): Jack has to spend t time units to put either of his feet on this block. 　 You can assume that it takes no time to put a foot on a block marked with 'S' or 'T'. Output For each dataset, print a line only having a decimal integer indicating the minimum time required for the cliff climbing, when Jack can complete it. Otherwise, print a line only having "-1" for the dataset. Each line should not have any characters other than these numbers. Sample Input 6 6 4 4 X X T T 4 7 8 2 X 7 3 X X X 1 8 1 2 X X X 6 1 1 2 4 4 7 S S 2 3 X X 2 10 T 1 1 X 1 X 1 X 1 1 1 X 1 X 1 1 1 X S S 2 10 T X 1 X 1 X 1 X 1 1 1 X 1 X 1 1 1 X S S 10 10 T T T T T T T T T T X 2 X X X X X 3 4 X 9 8 9 X X X 2 9 X 9 7 7 X 7 3 X X 8 9 X 8 9 9 9 6 3 X 5 X 5 8 9 9 9 6 X X 5 X 5 8 6 5 4 6 8 X 5 X 5 8 9 3 9 6 8 X 5 X 5 8 3 9 9 6 X X X 5 X S S S S S S S S S S 10 7 2 3 2 3 2 3 2 3 T T 1 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 4 3 2 3 2 3 2 3 2 3 5 3 2 3 1 3 2 3 2 3 5 2 2 3 2 4 2 3 2 3 5 S S 2 3 2 1 2 3 2 3 0 0 Sample Output 12 5 -1 22 12

String s = new String(" a ") 到底产生几个对象？

Linux面试题（2020最新版）

JVM内存结构和Java内存模型别再傻傻分不清了

JVM内存结构和Java内存模型都是面试的热点问题，名字看感觉都差不多，网上有些博客也都把这两个概念混着用，实际上他们之间差别还是挺大的。 通俗点说，JVM内存结构是与JVM的内部存储结构相关，而Java内存模型是与多线程编程相关，本文针对这两个总是被混用的概念展开讲解。 JVM内存结构 JVM构成 说到JVM内存结构，就不会只是说内存结构的5个分区，而是会延展到整个JVM相关的问题，所以先了解下

loonggg读完需要3分钟速读仅需 1 分钟大家好，我是你们的校长。我之前讲过，这年头，只要肯动脑，肯行动，程序员凭借自己的技术，赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

85后蒋凡：28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门，他的人生底层逻辑是什么？...

MySQL数据库面试题（2020最新版）

HashMap底层实现原理，红黑树，B+树，B树的结构原理 Spring的AOP和IOC是什么？它们常见的使用场景有哪些？Spring事务，事务的属性，传播行为，数据库隔离级别 Spring和SpringMVC，MyBatis以及SpringBoot的注解分别有哪些？SpringMVC的工作原理，SpringBoot框架的优点，MyBatis框架的优点 SpringCould组件有哪些，他们...