最后一场了,比赛前就希望这场不要是自闭场,然后前半场做的时候好自闭,不过后半场就很欢乐了 也许这就是ACM比赛的乐趣所在吧
1004 Permutation Counting
题意:a数列是全排列,b数列是由a数列决定的,b[i] = a[i+1] > a[i] ? 0 : 1,a数列的长度为n,b数列的长度为n-1,给定b数列,问有多少种a数列
和队友一起想了两个多小时,还是不会,自闭了,我就去做1003去了, 然后队友就过了这题orz , 太强了
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 5e3 + 7;
const int MOD = 1e9 + 7;
// const int INF = ;
// const double eps = ;
// const double PI = acos(-1);
// const int DIRX[] = {};
// const int DIRY[] = {};
int T;
int n;
bool b[MAXN];
int dp[MAXN][MAXN];
int ans;
int32_t main(void)
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> T;
while (T--)
{
memset(dp, 0, sizeof(dp));
cin >> n;
for (int i = 2; i <= n; ++i)
{
cin >> b[i];
}
dp[1][1] = 1;
for (int i = 2; i <= n; ++i)
{
if (b[i] == 0)
{
for (int j = 2; j <= i; ++j)
{
dp[i][j] = (dp[i - 1][j - 1] + dp[i][j - 1]) % MOD;
}
}
else
{
for (int j = i; j >= 1; --j)
{
dp[i][j] = (dp[i - 1][j] + dp[i][j + 1]) % MOD;
}
}
}
ans = 0;
for (int i = 1; i <= n; ++i)
{
ans = (ans + dp[n][i]) % MOD;
}
ans %= MOD;
cout << ans << endl;
}
return 0;
}
1003 Mine Sweeper
读了下题,是阴间扫雷构造题
都玩过扫雷吧,扫雷里有很多格子有数字,也有些格子有地雷,现在把所有数字加起来,记作S,给定S,让你构造一个扫雷图,若构造不出输出-1
构造的扫雷图可以自定义行数和列数,不过行数要<=25,列数要<=25,S的范围是0~1000
分析:
复制下面的代码,输入几组数据就知道我是怎样构造的了
#include<iostream>
#include<algorithm>
using namespace std;
char graph[30][30];
int opx[8] = {-1,-1,-1,0,1,1,1,0};
int opy[8] = {-1,0,1,1,1,0,-1,-1};
void solve(int s){
//cout<<endl<<s<<endl;
int r, c, cs;
if(s==0){
cout<<1<<" "<<1<<endl<<"X"<<endl;
return;
}
if(s < 25){
r = 1; c = s + 1;
cout << r << " " << c << endl;
for(int j = 1;j<=c;j++){
if(j % 2) cout<<"X";
else cout<<".";
}
cout<<endl;
return;
}
if(s <= 73){
r = 2;
cs = (s - 4) / 3;
if( cs * 3 + 4 == s){
c = cs + 2;
cout<<r<<" "<< c << endl;
for(int j = 1;j <= c;j++){
cout<<"X";
}
cout<<endl;
for(int j = 1;j <= c;j++){
cout<<".";
}
cout<<endl;
return;
}
cs++;
if( cs * 3 + 4 - 1 == s){
c = cs + 2;
cout << r << " " << c << endl;
for(int j = 1;j <= c;j++){
cout<<"X";
}
cout<<endl;
cout<<"X";
for(int j = 2;j <= c;j++) {
cout<<".";
}
cout<<endl;
return;
}
c = cs + 2;
cout << r << " " << c << endl;
for(int j = 1;j <= c;j++){
cout<<"X";
}
cout<<endl;
cout<<"X";
for(int j = 2;j <= c - 1;j++){
cout<<".";
}
cout<<"X";
cout<<endl;
return;
}
for(int i = 1;i <= 25;i++){
for(int j = 1;j <= 25;j++){
graph[i][j] = ‘.‘;
}
}
int num = s / 8;
if(num <= 12) {
r = 3;
c = 2 * num + 1;
}
else{
int cs;
cs = num / 12;
if(cs * 12 < num) cs++;
r = 2 * cs + 1;
c = 25;
}
int px = 2, py = 2;
for(int e = 1;e <= num;e++){
graph[px][py] = ‘X‘;
py += 2;
if(py > 25){
py = 2;
px += 2;
}
}
int cnt;
cnt = s - num * 8;
px = 1; py = 1;
for(int i = 1;i <= cnt;i++){
graph[px][py] = ‘X‘;
py += 2;
}
cout << r << " " << c << endl;
int ans = 0;
for(int i = 1;i <= r;i++){
for(int j = 1;j <= c;j++){
cout<<graph[i][j];
//if(graph[i][j] == ‘.‘){
// for(int op = 0;op<8;op++){
// int dx = i + opx[op], dy = j + opy[op];
// if(graph[dx][dy] == ‘X‘) ans ++;
// }
//}
}
cout<<endl;
}
//cout<<ans<<endl;
return;
}
int main()
{
int T, s;
//for(int i = 1000;i ;i--){
// solve(i);
//}
cin>>T;
while(T--){
cin>>s;
solve(s);
}
return 0;
}
原文:https://www.cnblogs.com/ruanbaitql/p/13573599.html