# BestCoder Round #25 A, B

Source: Internet
Author: User

BestCoder Round #25 A, B

It was a good match, and it was completely overwhelmed by my own IQ... Yes ..

A. determine whether A directed graph contains loops. The data is small, simple, and crude. The Brute Force algorithm can be used. The brute-force enumeration has two relationships between vertices to determine whether the reverse direction can be found. If yes, there is a ring...

```# Include

# Include

# Include

# Include

# Include

# Include

# Include

# Include

# Include

# Include

# Include
# Include

# Define eps 1e-9 // # define M 1000100 // # define LL _ int64 # define LL long // # define INF 0x7ffffff # define INF 0x3f3f3f3f # define PI 3.1415926535898 # define zero (x) (fabs (x)

G [maxn]; int flag; void dfs (int x, int y) {if (x = y) {flag = 1; return;} if (vis [x]) return; vis [x] = 1; int n = g [x]. size (); for (int I = 0; I <n; I ++) dfs (g [x] [I], y);} int main () {int n; int m; while (cin> n> m) {int x, y; flag = 0; memset (mp, 0, sizeof (mp )); for (int I = 0; I <= n; I ++) g [I]. clear (); for (int I = 0; I <m; I ++) {scanf ("% d", & x, & y ); mp [x] [y] = 1; g [x]. push_back (y);} for (int I = 1; I <= n; I ++) {for (int j = 1; j <= n; j ++) {if (! Mp [I] [j]) continue; memset (vis, 0, sizeof (vis); dfs (j, I); if (flag) break;} if (flag) break;} if (flag) cout <"NO" <

B. dp questions. We will consider one row at a time. Dp [I] [j] indicates that the first line I meets the condition that each row has at least one gem, however, only column j meets the criteria for gemological use. Enumerate the number k of gems in row I + 1. t of these k stones are placed on the column without gems. Then we can get the transfer equation: dp [I + 1] [j + t] + = dp [I] [j] * c [m-j] [t] * c [j] [k-t], c [x] [y] indicates the number of all combinations of y elements unordered in x different elements.

The answer is clearly explained .. No more.

#include #include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include
#include

#define eps 1e-9///#define M 1000100///#define LL __int64#define LL long long///#define INF 0x7ffffff#define INF 0x3f3f3f3f#define PI 3.1415926535898#define zero(x) ((fabs(x)

= 0; t--) { if(m-j < 0 || k-t < 0) continue; dp[i+1][j+t] += (dp[i][j]*cnk[m-j][t]%mod)*cnk[j][k-t]%mod; dp[i+1][j+t] %= mod; } } } } cout<

```

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.