实力眼瞎, D n == 1 ans = 0, 我输出-1 分又没了
A
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int main() {
IO;
for (cin >> _; _; --_) {
cin >> n;
rep (i, 1, n) cout << i << ' ';
cout << '
';
}
return 0;
}
B
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int f[105][105];
char s[105][105];
int main() {
IO;
for (cin >> _; _; --_) {
cin >> n >> m;
int ans = 0;
rep (i, 1, n) {
cin >> s[i] + 1;
if (s[i][m] == 'R') ++ans;
}
rep (i, 1, m) if (s[n][i] == 'D') ++ans;
cout << ans << '
';
}
return 0;
}
C
不让你有回去得边, 即边数为 n - 1
对于 数字n 左右两边, 分别为升序和降序, 则边数必为 n - 1
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e6 + 5, mod = 1e9 +7;
int n, m, _, k;
int inv[N] = {0, 1}, a[N] = {1, 1}, b[N] = {1, 1};
int C(int x, int y) {
if (y == 0 || x == mod) return 1;
if (x < 0 || y < 0 || y > x) return 0;
return (ll)a[x] * b[y] % mod * b[x - y] % mod;
}
void init() {
rep (i, 2, n) {
inv[i] = (ll)(mod - mod / i) * inv[mod % i] % mod;
a[i] = (ll)a[i - 1] * i % mod;
b[i] = (ll)b[i - 1] * inv[i] % mod;
}
}
int main() {
IO;
cin >> n; init();
ll ans = 0;
rep (i, 1, n) {
ans = (ans + C(n - 1, i - 1)) % mod;
}
ans = (a[n] - ans + mod) % mod;
cout << ans;
return 0;
}
D
dp
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e6 + 5;
int n, m, _, k;
char s[N];
int f[N][8], v[N];
bool check(int a, int b) {
if (n == 2) return (__builtin_popcount(a) + __builtin_popcount(b)) % 2;
return (__builtin_popcount(a & 3) + __builtin_popcount(b & 3)) % 2
&& (__builtin_popcount(a >> 1) + __builtin_popcount(b >> 1)) % 2;
}
int main() {
IO;
cin >> n >> m;
if (n >= 4 && m >= 4) { cout << -1; return 0; };
if (n == 1 || m == 1) { cout << 0; return 0; }
memset(f, 0x3f, sizeof f);
rep (i, 0, n - 1) {
cin >> s;
rep (j, 0, m - 1)
if (s[j] == '1') v[j] |= 1 << i;
}
rep (i, 0, m - 1)
rep (j, 0, (1 << n) - 1) {
if (i == 0) f[i][j] = 0;
else rep (k, 0, (1 << n) - 1) if (check(k, j)) f[i][j] = min(f[i - 1][k], f[i][j]);
f[i][j] += __builtin_popcount(j ^ v[i]);
//cout << i << ' ' << j << ' ' << f[i][j] << '
';
}
cout << *min_element(f[m - 1], f[m - 1] + 8);
return 0;
}