BestCoder Round #16
这场挫掉了,3挂2,都是非常sb的错误 23333 QAQ
A:每一个数字。左边个数乘上右边个数,就是能够组成的区间个数,然后乘的过程注意取模不然会爆掉
B:dp,dp[i][2]记录下第一长的LIS,和第二长的LIS。哎,转移的时候一个地方写挫掉了导致悲剧啊QAQ
C:首先假设知道Nim游戏的,就非常easy转化问题为。一些数字能否选几个能否异或和为0。那么就是每一个数字拆成40位。然后每一位异或和为0。这样就能够构造出40个方程,然后高斯消元求解,假设有自由变元就是有解。由于必定有一个全是0的解。而由于不能全取,所以这个解是错误的,那么就变成推断自由变元个数了,还是一个地方写挫掉了悲剧啊QAQ
代码:
A:
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 500005;
const ll MOD = 1000000007;
int t, n;
ll a;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
ll ans = 0;
for (ll i = 0; i < n; i++) {
scanf("%I64d", &a);
ans = (ans + a * (n - i) % MOD * (i + 1) % MOD) % MOD;
}
printf("%I64d\n", ans);
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1005;
int t, n, a[N], dp[N][2];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int ans0 = 0, ans1 = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
dp[i][0] = 1; dp[i][1] = 0;
for (int j = 1; j < i; j++) {
if (a[i] <= a[j]) continue;
if (dp[i][0] <= dp[j][0] + 1) {
dp[i][1] = dp[i][0];
dp[i][0] = dp[j][0] + 1;
} else if (dp[i][1] < dp[j][0] + 1) {
dp[i][1] = dp[j][0] + 1;
}
dp[i][1] = max(dp[i][1], dp[j][1] + 1);
}
if (ans0 <= dp[i][0]) {
ans1 = ans0;
ans0 = dp[i][0];
} else if (ans1 < dp[i][0]) ans1 = dp[i][0];
ans1 = max(ans1, dp[i][1]);
}
printf("%d\n", ans1);
}
return 0;
}
C:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1005;
int t, n, A[45][N];
ll a;
int rank(int m, int n) {
int i = 0, j = 0, k, r, u;
while (i < m && j < n) {
r = i;
for (k = i; k < m; k++)
if (A[k][j]) {r = k; break;}
if (A[r][j]) {
if (r != i) for(k = 0; k <= n; k++) swap(A[r][k], A[i][k]);
for (u = i + 1; u < m; u++) if (A[u][j])
for (k = i; k <= n; k++) A[u][k] ^= A[i][k];
i++;
}
j++;
}
return n - i;
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
memset(A, 0, sizeof(A));
for (int i = 0; i < n; i++) {
scanf("%lld", &a);
for (int j = 0; j < 40; j++)
A[j][i] = (a>>j)&1;
}
printf("%s\n", rank(40, n) > 0 ?
"Yes" : "No"); } return 0; }
版权声明:本文博客原创文章,博客,未经同意,不得转载。