# 250

### Problem Statement

The idols Ami and Mami like playing games. Today they bought a new game. At the beginning of the game a single slime appears on the screen. You are given an intS: the size of the slime.

The game consists of K turns. In each turn of the game the player must choose a single slime and cut it into two smaller parts. More precisely, suppose that the player chose a slime of size z. When cutting this slime, the player must choose two positive integers x and y such that x+y = z. The player will then cut the slime into two smaller slimes. The sizes of those smaller slimes will be x and y, respectively. Note that the player must always choose a slime of size 2 or more, as it is not possible to cut a slime of size 1.

The player gets a reward for making each cut: whenever you cut a slime of size x+y into slimes of sizes x and y, the player is awarded x*y mascots.

Ami and Mami have just started a new game. You are given two ints S andM. Calculate and return the smallest possible K (the number of turns in the game) such that Ami and Mami can get at leastM mascots in the game. If there exists no such K, return -1 instead.

### Definition

 Class: SubdividedSlimes Method: needCut Parameters: int, int Returns: int Method signature: int needCut(int S, int M) (be sure your method is public)

### Limits

 Time limit (s): 2 Memory limit (MB): 256 Stack limit (MB): 256

### Constraints

- S will be between 2 and 1000, inclusive.
- M will be between 1 and 10^9, inclusive.

### Examples

0)

 3 2
Returns: 1
 There is a single slime of size 3, and the players have to get at least two mascots. In this case, K = 1 is sufficient. In the only step, cut the only slime into two slimes with sizes 1 and 2. (This gives them 1*2 = 2 mascots.)
1)

 3 3
Returns: 2
 There is a single slime of size 3, and the players have to get at least three mascots. They can get three mascots in two steps: In the first step, cut the only slime into two slimes with sizes 1 and 2. (This gives them 1*2 = 2 mascots.) In the second step, choose the slime of size 2 and cut it into two slimes of size 1 each. (This gives them 1*1 = 1 mascot.) The total number of mascots they obtained is 2 + 1 = 3.
2)

 3 4
Returns: -1
 There is a single slime of size 3. The players cannot get 4 mascots in any way.
3)

 765 271828
Returns: 14

#include <cstdio>
#include <iostream>
#include <string>
#include<assert.h>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
typedef long long int ll;
#define rp(i,b) for(int i=(0),__tzg_##i=(b);i<__tzg_##i;++i)
#define rep(i,a,b) for(int i=(a),__tzg_##i=(b);i<__tzg_##i;++i)
#define repd(i,a,b) for(int i=(a),__tzg_##i=(b);i<=__tzg_##i;++i)
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
struct SubdividedSlimes {
int needCut(int S, int M) {
rep(i,2,S+1) {
int a = S/(i), b = S%(i), s = S;
int r = 0;
rep(j, 0, i) {
int d = a;
if (j+b >= i)
++d;
r += d*(s-d);
s -= d;
}
if (r >= M)
return i-1;
}
return -1;
}
};

# 500

### Problem Statement

Given are ints N and L.

A complete graph is a graph in which each pair of vertices is connected by exactly one undirected edge.

A graph is called beautiful if:

• It is a complete graph on N vertices.
• Each edge has an associated cost, and all these costs are integers between 1 andL, inclusive.
Hence, there are exactly L^(N*(N-1)/2) different beautiful graphs.

The minimum spanning tree (MST) of a beautiful graph is its subgraph with the following properties:

• The subgraph contains all N vertices.
• The subgraph is connected. (I.e., it is possible to get from any vertex to any other vertex using only edges that belong to the subgraph.)
• The total cost of edges in the subgraph is as small as possible.
A single beautiful graph can have multiple MSTs. (Each of these MSTs will contain a different set of edges, but they will have the same total cost.)

An MST is called a line if the degree of each of its vertices is at most 2.

Hibiki likes MSTs. She also likes lines. For each beautiful graph G, let f(G) be the number of its MSTs that are lines. (Note that for some beautiful graphs it may be the case that f(G)=0.)

Let X be the sum of the values f(G) over all beautiful graphs G. Please calculate X for her. As X can be very large, compute and return the value (X modulo 1,000,000,007).

### Definition

 Class: LineMST Method: count Parameters: int, int Returns: int Method signature: int count(int N, int L) (be sure your method is public)

### Limits

 Time limit (s): 2 Memory limit (MB): 256 Stack limit (MB): 256

### Constraints

- N will be between 2 and 200, inclusive.
- L will be between 1 and 200, inclusive.

### Examples

0)

 3 2
Returns: 15
 Beautiful graphs are complete graphs on 3 vertices in which each edge has cost either 1 or 2. There are 8 such graphs. Some of these graphs have more than one MST. For example, the graph in which each edge has cost 1 has three different MSTs. In this case, each of those three MSTs is a line, so we count each of them.
1)

 2 10
Returns: 10
 There are 10 beautiful graphs and f(G) is 1 for each of them.
2)

 3 1
Returns: 3
 Now there is only one beautiful graph. As we already explained in Example 0, this graph has 3 MSTs and each of those is a line.
3)

 8 41
Returns: 655468587
4)

 200 200
Returns: 152699064

dp(n,M) = dp(n, M-1) + sum(dp(i,M-1)*dp(n-i, M)*(i*(n-i)-1)^(L-M+1)) {1<=i<n}

#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;
typedef long long ll;
#define urp(i,a,b) for(int i=(a),__tzg_##i=(b); i>=__tzg_##i; --i)
#define rp(i,b) for(int i=(0), __tzg_##i=(b);i<__tzg_##i;++i)
#define rep(i,a,b) for(int i=(a), __tzg_##i=(b);i<__tzg_##i;++i)
#define repd(i,a,b) for(int i=(a), __tzg_##i=(b);i<=__tzg_##i;++i)
#define mst(a,b) memset(a,b,sizeof(a))
typedef pair<int,int> pii;
#define px first
#define py second
const ll mod = 1000000007;
const int MAXN = 220;
const int MAXM = 15;
const double eps = 1e-6;
#define mp(a,b) make_pair(a,b)
typedef vector<int> VI;
typedef vector<double> VDB;
typedef vector<ll> VL;
typedef vector<pii> VPII;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
struct LineMST {
int count(int N, int L) {
VVL dp(N+1, VL(L+1, 0));
VVL pow(L+1, VL(N*N+1, 1));
rep(i, 1, L+1) rep(j, 1, N*N+1) {
pow[i][j] = pow[i][j-1] * i % mod;
}
dp[1] = VL(L+1, 1);
rep(i, 2, N+1) {
rep(j, 1, L+1) {
dp[i][j] = dp[i][j-1];
rep(k, 1, i) {
dp[i][j] = (dp[i][j] + dp[k][j-1]*dp[i-k][j]%mod*pow[L+1-j][k*(i-k)-1]) % mod;
}
}
}
ll res = dp[N][L];
rep(i, 3, N+1)
res = res*i%mod;
return res;
}
};

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120