您的位置:首页 > 其它

Codeforces #309(div2)

2015-06-26 01:04 246 查看
A. Kyoya and Photobooks

题意: 给一个长度不大于20的字符串任意一个位置插入一个a-z 求一共有多少新字符串的可能

思路: |s|很小 所以直接暴力找出所有的新串 set暴力求出多少个  这题的规律是 |s|*25 + 1

参考code:

//
//  Created by TaoSama on 2015-06-25
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

string s;

int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
//  freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);

while(cin >> s) {
set<string> ss;
for(int i = 0; i <= s.size(); ++i) {
for(char c = 'a'; c <= 'z'; ++c) {
string t = s;
t.insert(i, 1, c);
ss.insert(t);
}
}
cout << ss.size() << '\n';
}
return 0;
}

B. Ohana Cleans Up

题意: 给定01矩阵 每次只能翻转一列 问这样不限次数操作后 最多的行全为1的个数

思路: 由于至少得有1行吧 暴力把尝试把每一行都搞成全1 在这种情况下全1行数有多少 不断更新ans  O(n^3) 这题可过

参考code:

//
//  Created by TaoSama on 2015-06-25
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

int n;
bool a[105][105], t[105][105];

int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
//  freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);

while(scanf("%d", &n) == 1) {
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
scanf("%1d", &a[i][j]);

int ans = 0;
for(int i = 1; i <= n; ++i) {
memcpy(t, a, sizeof a);
for(int j = 1; j <= n; ++j) {
if(!a[i][j]) {
for(int k = 1; k <= n; ++k) {
t[k][j] ^= 1;
}
}
}
int cnt = 0;
for(int j = 1; j <= n; ++j) {
bool ok = true;
for(int k = 1; k <= n; ++k) {
if(!t[j][k]) {
ok = false;
break;
}
}
if(ok) ++cnt;
}
ans = max(ans, cnt);
}
printf("%d\n", ans);
}
return 0;
}

C. Kyoya and Colored Balls

题意: k种颜色的球 每种有不超过1000个 取出i颜色球最后一个一定在i+1颜色球最后一个的前面 问多少种取法

思路: 考虑倒着想 先把最后一种颜色的拿出一个放在最后 那么其他a[k] - 1个球可以任意放在sum-1个的位置 即方法数C sum-1_a[k]-1

同理前面的球 先放一个在最后然后 在sum-=前一个个数的情况  方法数为C sum-1_a[k-1]-1 求个乘积就好

考虑顺着想:  




图片来自: http://www.cnblogs.com/justPassBy/p/4600118.html

参考code:

By TaoSama, contest: Codeforces Round #309 (Div. 2), problem: (C) Kyoya and Colored Balls, Accepted, #
//
//  Created by TaoSama on 2015-06-25
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

long long n, a[1005], c[1005][1005];

void InitC() {
for(int i = 0; i <= 1000; ++i) {
for(int j = 0; j <= i; ++j)
if(i == j || j == 0) c[i][j] = 1;
else c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
}
}

int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
//  freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);

InitC();
while(cin >> n) {
int sum = 0;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
sum += a[i];
}

long long ans = 1;
for(int i = n; i >= 1; --i) {
ans = ans * c[sum - 1][a[i] - 1] % MOD;
sum -= a[i];
}
cout << ans << '\n';
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: