CSU 1908: The Big Escape 1909: Perfect Chocolate 1911: Card Game 1912: One Boring Problem
阿新 • • 發佈:2019-01-30
#include <iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
#include<string.h>
#include<cmath>
#include<cstdio>
using namespace std;
const int maxn = 150000+10;
int erear,head[maxn];
int root,n;
int vis[maxn];
int cnt[maxn];
int ans = -1;
int kase = 1;
struct node
{
int x,to,next;
}E[maxn];
void __init__()
{
memset(head,-1,sizeof(head));
erear = 0;
}
void build(int x,int y)
{
E[erear].x = x;
E[erear].to= y;
E[erear].next = head[x];
head[x] = erear++;
}
int dfs(int root,int &sum)
{
for(int i = head[root]; i!=-1 ;i = E[i].next)
{
if(vis[E[i].to]==0)
{
vis[E[i].to] = 1;
sum++;
dfs(E[i].to,sum);
}
}
}
int main()
{
while(~scanf("%d%d",&n,&root))
{
__init__();
ans = 0;
memset (vis,0,sizeof(vis));
memset(cnt,0,sizeof(cnt));
for(int i = 0;i < n-1;i++)
{
int x,y;
scanf("%d%d",&x,&y);
build(x,y);
build(y,x);
}
vis[root] = 1;
for(int i = head[root];i!=-1 ;i=E[i].next)
{
int sum = 1;
vis[E[i].to] = 1;
dfs(E[i].to,sum);
ans = max(sum,ans);
/*if(kase == 10003)
cout<<sum<<endl;*/
}
cout<<"Case #"<<kase++<<":"<<ans<<endl;
}
return 0;
}
#include <cstdio>
#include <cstring>
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
using namespace std;
const int MAXN = 1e5 + 5;
const int SIZE = 2e5 + 5;
char S[MAXN];
int main(){
int cas = 1;
while(~scanf("%s", S)){
int len = strlen(S);
int sum = 0;
for(int i = 0;i < len;i ++){
if(S[i] == '1') sum ++;
else sum --;
}
if(sum < 0) sum = -sum;
if(sum > 0) sum --;
printf("Case #%d:%d\n",cas ++, sum);
}
return 0;
}
#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
using namespace std;
typedef long long LL;
const int MAXN=1<<18;
int a[MAXN],b[MAXN];
char tmp[20];
void FWT(int a[],int n)
{
for(int d=1;d<n;d<<=1)
for(int m=d<<1,i=0;i<n;i+=m)
for(int j=0;j<d;j++)
{
int x=a[i+j],y=a[i+j+d];
//xor:a[i+j]=x+y,a[i+j+d]=(x-y+mod)%mod;
//and:a[i+j]=x+y;
a[i+j+d]=x+y;
}
}
void UFWT(int a[],int n)
{
for(int d=1;d<n;d<<=1)
for(int m=d<<1,i=0;i<n;i+=m)
for(int j=0;j<d;j++)
{
int x=a[i+j],y=a[i+j+d];
//xor:a[i+j]=(x+y)/2,a[i+j+d]=(x-y)/2;
//and:a[i+j]=x-y;
a[i+j+d]=y-x;
}
}
int main()
{
int T,cas=0;
scanf("%d",&T);
while(T--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int n,m,q;
scanf("%d%d",&n,&m);
int tot=1<<m;
for(int i=0;i<n;i++)
{
scanf("%s",tmp);
int len=strlen(tmp);
int t=0;
for(int j=0;j<len;j++)
{
t<<=1;
t|=(tmp[j]-'0');
}
a[t]++;
}
// for(int i=0;i<=12;i++)
// cout<<a[i]<<" ";
// cout<<endl;
for(int i=0;i<n;i++)
{
scanf("%s",tmp);
int len=strlen(tmp);
int t=0;
for(int j=0;j<len;j++){
t<<=1;
t|=(tmp[j]-'0');
}
b[t]++;
}
// for(int i=0;i<=14;i++)
// cout<<b[i]<<" ";
// cout<<endl;
FWT(a,tot); FWT(b,tot);
for(int i=0;i<tot;++i)
a[i]=a[i]*b[i];
UFWT(a,tot);
scanf("%d",&q);
printf("Case #%d:\n",++cas);
while(q--)
{
int t=0;
scanf("%s",tmp);
int len=strlen(tmp);
for(int i=0;i<len;i++)
{
t<<=1;
t|=(tmp[i]-'0');
}
printf("%d\n",a[t]);
}
}
return 0;
}
#include <cstdio>
#include <cstring>
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
using namespace std;
typedef long long LL;
const int MAXN = 3e5 + 5;
const int SIZE = 2e5 + 5;
const int mod = 1e9 + 7;
LL CC[MAXN];
LL CCD[MAXN];
LL mod_pow(LL x, LL n, LL p){
LL ret = 1;
while(n){
if(n & 1) ret = ret * x % p;
x = x * x % p;
n >>= 1;
}
return ret;
}
void CC_init(){
CC[0] = CC[1] = 1;
CCD[0] = 1;
CCD[1] = 1;
for(int i = 2;i < MAXN;i ++){
CC[i] = CC[i - 1] * i % mod;
CCD[i] = mod_pow(CC[i], mod - 2, mod) % mod;//乘法逆元
}
}
LL C(int m, int n, LL p){
if(m > n) return 0;
if(n - m < m) m = n - m;
LL up = 1, down = 1;
up = CC[n] * CCD[n - m] % p;
down = CCD[m];
return up * down % p;
}
LL lucas(int m, int n, LL p){
if(m == 0) return 1;
return C(m % p, n % p, p) * lucas(m / p, n / p, p) % p;
}
int n, m;
int main(){
CC_init();
while(~scanf("%d%d", &n, &m)){
LL ans = 0, tmp = 0;
if(m == 1){
printf("1\n");
continue;
}
n = n - m;
for(int i = 1;i <= n;i ++){
ans = (ans + lucas(m - 1 - 1, n - i + m - 1 - 1, mod)) % mod;//隔板法或者叫做插板法
//printf("[%d]\n", ans);
tmp = 0;
int flag = 1;
for(int j = 1;j * i + i <= n && j < m;j ++){
tmp = (tmp + lucas(m - 1 - 1, n - i - j * i + m - 1 - 1, mod) * lucas(j, m - 1, mod) * flag % mod + mod) % mod;
flag = - flag;
}
ans = (ans + mod - tmp) % mod;
}
printf("%lld\n", ans);
}
return 0;
}