Birthday party Time Limit: 1000 ms memory limit: 65536 k any questions? Click Here ^_^ Subject description: Sherlock's birthday is coming soon. Sherlock plans to invite friends to join his birthday party. In order to make the party happy as much as possible, Sherlock found that every friend has a happy value. There is also a complex relationship between friends of Sherlock. When one or two friends appear at the same time in the Party, an additional happy value will be generated. Fortunately, there are not many friends in Sherlock, sherlock intends to invite some or all of its friends (or even none) so that the happy value of the Party can input up to multiple groups of data. First, an integer t indicates the number of groups to which the data is sent. The first line of each group of data is an integer N (0 <n <= 15), indicating the number of friends of Sherlock. The N integers in the second row indicate the happy values that each friend will generate if they come to the party. In the next n rows, there are n integers in each line, the J-th integer in line I indicates that when the I-th friend and J-th friend join the party at the same time, extra happy values are generated, the range of the happy value in the given data is (-100 ~ 100) Output a row of data in each group. The example input of the happy value with the highest party value of Sherlock
421 20 -2-2 03-1 -1 00 1 11 0 11 1 031 1 10 -1 -1-1 0 -1-1 -1 03-1 -1 -10 -2 -2-2 0 -2-2 -2 0
Sample output
2110
I have been thinking about DP before, and the result cannot push the state transition equation .. (Sad, my DP is a scum.) and mjj also said that this was the dp ak defense, and then he suddenly saw that the SCF was used for brute force search! Okay, I admit I have thought about it, but the BFS that I learned the day before yesterday cannot be typed out. The idea of making such a storm search is also quite different. For my friend, there are two statuses, so the complexity of a search is O (2 ^ 15), and no array is required. Hard search and rescue is enough.
# Include <cstdio> # include <cstdlib> # include <cstring> # include <iostream> # include <algorithm> # include <cmath> # include <queue> using namespace STD; typedef struct node {int A [20], ANS, X, top; // The number of friends who attended the party in the array}; int ma [20] [20]; int Fri [20], Max, N; void BFS () {node T, V; queue <node> q; T. top = 0; T. ans = 0; T. X =-1; q. push (t); While (! Q. empty () {v = Q. front (); q. pop (); If (v. X = N-1) // returns the maximum value of {If (max <v. ans) max = v. ans; continue;} // select either this person or T. X = v. X + 1; // do not select personal I t. ans = v. ans; T. top = v. top; For (INT I = 0; I <v. top; I ++) T. A [I] = v. A [I]; q. push (t); // select the I-th person t. top = v. top + 1; T. A [v. top] = T. x; T. ans = v. ans + Fri [T. x]; for (INT I = 0; I <v. top; I ++) T. ans + = ma [T. A [I] [T. x]; q. push (t) ;}} int main () {int T, I, j; CIN >>t; while (t --) {CIN >> N; for (I = 0; I <n; I ++) CIN> Fri [I]; for (I = 0; I <n; I ++) for (j = 0; j <n; j ++) CIN> ma [I] [J]; max =-1; BFS (); If (max <0) cout <"0" <Endl; elsecout <max <Endl;} return 0 ;}