Gym 101933
Gym 101933
B. Baby Bites水题直接模拟即可
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-9
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)+
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("data.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=a-1;i>=b;--i)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e5 + ;
int n;
int main() {
sf ( n );
char op[];
int flag = ;
for ( int i = ; i <= n ; i++ ) {
scanf ( "%s", op );
if ( op[] >= '' && op[] <= '' ) {
int temp = ;
int len = strlen ( op );
for ( int j = ; j < len ; j++ ) temp = temp * + op[j] - '';
if ( temp != i ) flag = ;
}
}
if ( flag ) printf ( "makes sense\n" );
else printf ( "something is fishy\n" );
return ;
}
C. Code Cleanups(难点)在于读题 读题读到自闭
题意: 给你一个数组a[ ] 表示a[ i ]产生一个垃圾,之后每天肮脏度增加1 ,肮脏度到达20时必须清理,问最少清理天数(注意每年的结束要将肮脏度变为0)
直接模拟即可
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-9
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)+
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("data.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=a-1;i>=b;--i)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e5 + ;
int n, vis[maxn];
int main() {
sf ( n );
for ( int i = , x ; i < n ; i++ ) sf ( x ), vis[x] = ;
int sum = , cnt = , ans = ;
for ( int i = ; i <= ; i++ ) {
sum += cnt;
if ( sum >= ) sum = , ans++, cnt = ;
if ( vis[i] ) cnt++;
}
if ( cnt || sum ) ans++;
printf ( "%d\n", ans );
return ;
}
E. Explosion Exploit 记忆化搜索
题意:你有n个士兵,敌方有m个士兵,每一个士兵都有一定的血量(最大为6),如果血量归零,则证明该士兵死亡。现在有d点伤害,每一点伤害都会以等概率分配给任意一个人。现在问你,敌方的m个士兵全都阵亡的概率。
题解:总共只有12个士兵用一个long long 就可以存好状态了 当status<1000000时表示敌军已经死完了
这个概率是倒推过来的
Dfs(status,num)表示状态为status,剩下num点伤害,对方阵亡的概率
ans += ( double ) mp[i][j] / ( double ) sum * res;//表示转移到下一个状态的概率
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#define pi acos(-1.0)
#define eps 1e-9
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)+
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("data.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=a-1;i>=b;--i)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = ;
const int mod = 1e9 + ;
int n, m, d, mp[][];
unordered_map<LL, double>dp;
LL getstatus() {
LL temp = ;
for ( int i = ; i <= ; i++ ) temp = temp * + mp[][i];
for ( int i = ; i <= ; i++ ) temp = temp * + mp[][i];
return temp;
}
double dfs ( LL status, int num ) {
if ( status < ) return ;
if ( num == ) return ;
if (dp.count(status)) return dp[status];
double ans = ;
int sum = ;
for ( int i = ; i < ; i++ )
for ( int j = ; j <= ; j++ ) sum += mp[i][j];
for ( int i = ; i < ; i++ ) {
for ( int j = ; j <= ; j++ ) {
if ( !mp[i][j] ) continue;
mp[i][j]--, mp[i][j - ]++;
LL sta=getstatus();
double res = dfs ( sta, num - );
dp[sta]=res;
mp[i][j - ]--, mp[i][j]++;
ans += ( double ) mp[i][j] / ( double ) sum * res;
}
}
return ans;
} int main() {
sfff ( n, m, d );
for ( int i = , x ; i <= n ; i++ ) {
sf ( x );
mp[][x]++;
}
for ( int i = , x; i <= m; i++ ) {
sf ( x );
mp[][x]++;
}
double ans = dfs ( getstatus(), d );
printf ( "%.8f\n", ans );
return ;
}
H. House Lawn
有一个 l 平方米的草坪,给你 m 台割草机。选择其中一台,在一周(10080分钟)的时间内割完草坪。每台割草机输入格式为:“名字,价格,割草效率,工作时间,充电时间” ;
要求选出价格最低的满足条件的一台,如果有多台满足条件且价格相同,按照输入顺序输出割草机名字。
一开始我以为只要一周内可以完成一次就好了,然后拿int写的,后面仔细看题要保证T周也必须清理T次,用int写的话你这周可以清理完,但是下周不一定。所有这题的就相当于充t分钟电能给割草(t/充电时间)*割草时间 所以用double写这题
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-9
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)+
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("data.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=a-1;i>=b;--i)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e2 + ;
string s[maxn], s1;
LL a[maxn], l, n, cnt[], vis[maxn];
int main() {
// FIN;
cin >> l >> n;
getchar();
int ans = INF;
for ( int i = ; i < n ; i++ ) {
getline ( cin, s1 );
int flag = , temp;
for ( int j = ; j < s1.size() ; j++ ) {
if ( s1[j] == ',' ) flag++, cnt[flag] = temp, temp = ;
else if ( !flag ) s[i] += s1[j];
else temp = temp * + s1[j] - '';
}
cnt[++flag] = temp;
a[i] = cnt[];
// int num = 10080 / ( cnt[4] + cnt[5] ), res = 10080 % ( cnt[4] + cnt[5] );
// for (int i=2 ;i<=5 ;i++) printf("%d%c",cnt[i],i==5?'\n':' ');
// printf ( "num = %d res = %d\n", num, res );
// LL sum = 0;
// if ( res >= cnt[4] ) sum = 1LL * ( num + 1 ) * 1LL * cnt[4] * 1LL * cnt[3];
// if ( res < cnt[4] ) sum = 1LL * num * 1LL * cnt[4] * 1LL * cnt[3] + 1LL * res * 1LL * cnt[3];
if ( ( double ) ( ( double ) / ( ( double ) ( cnt[] + cnt[] ) ) * ( double ) cnt[] * ( double ) cnt[] ) >= 1.0 * l && ans >= a[i] ) ans = cnt[],vis[i]=;
}
if ( ans == INF ) printf ( "no such mower\n" );
for ( int i = ; i < n ; i++ ) if ( ans == a[i] && vis[i]) cout << s[i] << endl;
return ;
}
Intergalactic Bidding
有n个人的名字和值,每个人的值相差两倍以上,问是否有一种方案使部分人的值加起来为S
大数直接模拟就好了(相差2倍以上,只有唯一解)
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-9
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)+
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("data.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=a-1;i>=b;--i)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int MAXL = ;
const int MAXN = ;
const int DLEN = ;
class Big {
public:
int a[MAXL], len;
Big ( const int b = ) {
int c, d = b;
len = ;
memset ( a, , sizeof ( a ) );
while ( d > MAXN ) {
c = d - ( d / ( MAXN + ) ) * ( MAXN + );
d = d / ( MAXN + );
a[len++] = c;
}
a[len++] = d;
}
Big ( const char *s ) {
int t, k, index, L;
memset ( a, , sizeof ( a ) );
L = strlen ( s );
len = L / DLEN;
if ( L % DLEN ) len++;
index = ;
for ( int i = L - ; i >= ; i -= DLEN ) {
t = ;
k = i - DLEN + ;
if ( k < ) k = ;
for ( int j = k; j <= i; j++ ) t = t * + s[j] - '';
a[index++] = t;
}
}
Big operator/ ( const LL &b ) const {
Big ret;
LL down = ;
for ( int i = len - ; i >= ; i-- ) {
ret.a[i] = ( a[i] + down * ( MAXN + ) ) / b;
down = a[i] + down * ( MAXN + ) - ret.a[i] * b;
}
ret.len = len;
while ( ret.a[ret.len - ] == && ret.len > ) ret.len--;
return ret;
}
bool operator> ( const Big &T ) const {
int ln;
if ( len > T.len ) return true;
else if ( len == T.len ) {
ln = len - ;
while ( a[ln] == T.a[ln] && ln >= ) ln--;
if ( ln >= && a[ln] > T.a[ln] ) return true;
else return false;
} else return false;
}
Big operator+ ( const Big &T ) const {
Big t ( *this );
int big = T.len > len ? T.len : len;
for ( int i = ; i < big; i++ ) {
t.a[i] += T.a[i];
if ( t.a[i] > MAXN ) {
t.a[i + ]++;
t.a[i] -= MAXN + ;
}
}
if ( t.a[big] != ) t.len = big + ;
else t.len = big;
return t;
}
Big operator- ( const Big &T ) const {
int big;
bool flag;
Big t1, t2;
if ( *this > T ) {
t1 = *this;
t2 = T;
flag = ;
} else {
t1 = T;
t2 = *this;
flag = ;
}
big = t1.len;
for ( int i = ; i < big; i++ ) {
if ( t1.a[i] < t2.a[i] ) {
int j = i + ;
while ( t1.a[j] == ) j++;
t1.a[j--]--;
while ( j > i ) t1.a[j--] += MAXN;
t1.a[i] += MAXN + - t2.a[i];
} else t1.a[i] -= t2.a[i];
}
t1.len = big;
while ( t1.a[t1.len - ] == && t1.len > ) {
t1.len--;
big--;
}
if ( flag ) t1.a[big - ] = - t1.a[big - ];
return t1;
}
LL operator% ( const int &b ) const {
LL d = ;
for ( int i = len - ; i >= ; i-- ) d = ( ( d * ( MAXN + ) ) % b + a[i] ) % b;
return d;
}
Big operator* ( const Big &T ) const {
Big ret;
int i, j, up, temp, temp1;
for ( i = ; i < len; i++ ) {
up = ;
for ( j = ; j < T.len; j++ ) {
temp = a[i] * T.a[j] + ret.a[i + j] + up;
if ( temp > MAXN ) {
temp1 = temp - temp / ( MAXN + ) * ( MAXN + );
up = temp / ( MAXN + );
ret.a[i + j] = temp1;
} else {
up = ;
ret.a[i + j] = temp;
}
}
if ( up != ) ret.a[i + j] = up;
}
ret.len = i + j;
while ( ret.a[ret.len - ] == && ret.len > ) ret.len--;
return ret;
}
void print() {
printf ( "%d", a[len - ] );
for ( int i = len - ; i >= ; i-- ) printf ( "%04d", a[i] );
}
};
int n;
struct node {
char name[];
char num[];
} qu[MAXL];
int cmp ( node s1, node s2 ) {
int len1 = strlen ( s1.num ), len2 = strlen ( s2.num );
if ( len2 > len1 ) return ;
else if ( len2 < len1 ) return ;
else {
for ( int i = ; i < len1 ; i++ )
if ( s2.num[i] < s1.num[i] ) return ;
else if ( s2.num[i] > s1.num[i] ) return ;
}
}
char sum[];
Big s, a[MAXL];
vector<int>ans;
int main() {
scanf ( "%d%s", &n, sum );
s = sum;
for ( int i = ; i < n ; i++ ) scanf ( "%s%s", qu[i].name, qu[i].num ) ;
sort ( qu, qu + n, cmp );
//for ( int i = 0 ; i < n ; i++ ) printf ( "%s %s\n", qu[i].name, qu[i].num );
for ( int i = ; i < n ; i++ ) a[i] = qu[i].num;
int flag = ;
for ( int i = n - ; i >= ; i-- ) {
// a[i].print(), printf ( " " ), s.print(), printf ( "\n" );
if ( a[i] > s ) continue;
else if ( s > a[i] ) {
s = s - a[i];
ans.push_back ( i );
} else {
ans.push_back ( i );
flag = ;
break;
}
}
if ( !flag ) printf ( "0\n" );
else {
printf ( "%d\n", ans.size() );
for ( int i = ; i < ans.size() ; i++ )
printf ( "%s\n", qu[ans[i]].name );
}
return ;
}
J. Jumbled String
有a个00子顺序串,b个01,c个10,d个11,构造01串
注意一点当全部等于0的时候要输出0或者1
还有a==0 ,0的个数有0或者1个 ,d==0 同理
我的构造是111100001111 然后再0之中插入一个1构造01和10
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-9
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)+
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("data.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=a-1;i>=b;--i)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e2 + ;
map<LL, int>mp;
LL a, b, c, d;
int main() {
for ( int i = ; i <= ; i++ ) mp[ ( i - ) *i / ] = i;
scanf ( "%lld%lld%lld%lld", &a, &b, &c, &d );
int num0 = mp[a], num1 = mp[d];
if ( a == && b == && c == && d == ) return * printf ( "1\n" );
if ( ( num0 == && a != ) || ( num1 == && d != ) ) return * printf ( "impossible\n" );
if ( num0 == && ( b || c ) ) num0 = ;
if ( num1 == && ( b || c ) ) num1 = ;
if ( num0 * num1 != b + c ) return * printf ( "impossible\n" );
if ( num0 == && b == && c == ) {
for ( int i = ; i < num1 ; i++ ) printf ( "" );
printf ( "\n" );
return ;
}
if ( num1 == && b == && c == ) {
for ( int i = ; i < num0 ; i++ ) printf ( "" );
printf ( "\n" );
return ;
}
//printf ( "num0 = %d num1 = %d\n", num0, num1 );
int cnt = c / num0, res = c % num0;
for ( int i = ; i < cnt ; i++ ) printf ( "" );
for ( int i = ; i < num0 - max ( res - ( res == ), ) ; i++ ) printf ( "" );
if ( res != ) printf ( "" ), num1--;
for ( int i = ; i < max ( res - ( res == ), ) ; i++ ) printf ( "" );
for ( int i = cnt ; i < num1 ; i++ ) printf ( "" );
printf ( "\n" );
return ;
}
K. King's Colors
给你一颗树有n个节点,用K种颜色染色,必要用完K种颜色,问方案数
第一次遇到容斥的题目,表示很不会
全部的方案为k*(k-1)^(n-1)-(k-1)*(k-1-1)^ (n-1)+ (k-2)*(k-2-1)^ (n-1)+……
我第一次看到这个式子很懵逼 后面解释是k*(k-1)^(n-1)这个包含了用了k-1的颜色的情况所以要减去
我第一次感觉减去这个就够了,但是这个式子还+上了k-2的颜色的情况 (我第一次想的时候k*(k-1)^(n-1)也包含了k-2的颜色的情况 为什么这里还要加上 直接减去不就好了)
然后我直接手写了一个4个节点和4种颜色的情况弄懂了
所有情况4*3*3*3 – 3*2*2*C(4,3)+C(4,2)*2*1*1*1
看3*2*2*C(4,3)这一项 选择3种颜色的方案数,这个里面包含了选择2种颜色的情况
假设抽出这3种颜色这里的两种颜色为
1 2 3 为 (1,2)(1,3),(2,3)
1 3 4 为 (1,3)(1,4),(3,4)
1 2 4 为 (1,2)(1,4),(2,4)
2 3 4 为 (2,3)(2,4),(3,4)
然后你会发现用了两种颜色的刚好多被减了一次,所以要加上
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-9
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)+
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("data.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=a-1;i>=b;--i)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = ;
const int mod = 1e9 + ;
int n, k, C[maxn][maxn];
LL exp_mod ( LL a, LL b ) {
LL ret = ;
while ( b ) {
if ( b & ) ret = ret * a % mod;
a = a * a % mod;
b = b >> ;
}
return ret % mod;
}
int main() {
C[][] = , C[][] = ;
for ( int i = ; i <= ; i++ ) {
C[i][] = , C[i][i + ] = ;
for ( int j = ; j <= i ; j++ )
C[i][j] = ( C[i - ][j - ] + C[i - ][j] ) % mod;
}
sff ( n, k );
for ( int i = , u ; i < n ; i++ ) sf ( u );
LL ans = ;
for ( int i = k ; i >= ; i-- )
if ( ( k - i ) % == ) ans = ( ans + 1LL * i * exp_mod ( i - , n - ) % mod * C[k][i] % mod ) % mod;
else ans = ( ans - 1LL * i * exp_mod ( i - , n - ) % mod * C[k][i] % mod + mod ) % mod;
printf ( "%lld\n", ans );
}
Gym 101933的更多相关文章
- CF gym 101933 K King's Colors —— 二项式反演
题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...
- Gym .101933 Nordic Collegiate Programming Contest (NCPC 2018) (寒假gym自训第四场)
(本套题算是比较温和吧,就是罚时有点高. B .Baby Bites 题意:给出一个婴儿给出的数组,有一些数字听不清楚,让你还原,问它是否是一个从1开始的一次增加的数组. 思路:从左往右依次固定,看是 ...
- CF gym 101933 K. King's Colors(二项式反演)
传送门 解题思路 首先给出的树形态没用,因为除根结点外每个点只有一个父亲,它只需要保证和父亲颜色不同即可.设\(f(k)\)表示至多染了\(k\)种颜色的方案,那么\(f(k)=(k-1)^{(n-1 ...
- 2019年湖南多校第一场||2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)
第一场多校就打的这么惨,只能说自己太菜了,还需继续努力啊- 题目链接: GYM链接:https://codeforces.com/gym/101933 CSU链接:http://acm.csu.edu ...
- CF gym101933 K King's Colors——二项式反演
题目:http://codeforces.com/gym/101933/problem/K 每个点只要和父亲不同色就行.所以 “至多 i 种颜色” 的方案数就是 i * ( i-1 )n-1 . #i ...
- 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) D. Delivery Delays (二分+最短路+DP)
题目链接:https://codeforc.es/gym/101933/problem/D 题意:地图上有 n 个位置和 m 条边,每条边连接 u.v 且有一个距离 w,一共有 k 个询问,每个询问表 ...
- 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) A. Altruistic Amphibians (DP)
题目链接:https://codeforc.es/gym/101933/problem/A 题意:有 n 只青蛙在一个坑里面,要求可以跳出坑的青蛙的最大数量.每个青蛙有 3 种属性:l 为青蛙一次可以 ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
随机推荐
- cobbler部署以及使用
常用软件安装及使用目录 资源链接:https://pan.baidu.com/s/1yfVnuSgY5vOTh-B74tpVyw 网盘分享的文件在此 cobbler第一次操作history. ec ...
- Python3中的函数 大全
Python 函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.Python提供了许多内建函数,比如print().但也可以自己创建 ...
- sqlplus远程连接oracle
格式: sqlplus 用户名/密码@192.168.19.189:1521/MYTEST MYTEST 数据库名称
- 面向对象OO第1-3次作业总结
面向对象OO第1-3次作业总结 学习OO已经四周了,对OO以及JAVA的编程也算终于了解了一丢丢.现在做完了三次的编程作业,对前三次的作业做一次总结. 第一次作业 ------------------ ...
- C++:构造函数3——浅拷贝和深拷贝
一.默认拷贝构造函数 拷贝构造函数是一种特殊的构造函数(详情见:http://www.cnblogs.com/duwenxing/p/7429777.html),如果用户在定义类时没有显式地编写拷贝构 ...
- cocos2d-x 相关文章资源(安卓开发)
http://blog.csdn.net/sdhjob/article/details/38734993 http://www.cnblogs.com/code4app/p/4026665.html ...
- IO文件的读取,以及写入文件内容
package zxc; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.Fi ...
- Calculator项目的过程及感受
1.将Calculator项目传到Github上的链接地址:https://github.com/sonnypp/object-oriented/tree/master/Calculator 2.本次 ...
- BloomFilter——大规模数据处理利器(爬虫判重)
http://www.cnblogs.com/heaad/archive/2011/01/02/1924195.html Bloom Filter是由Bloom在1970年提出的一种多哈希函数映射的快 ...
- build.xml
下载ant 解压ant 后设置ANT_HOME, PATH中添加ANT_HOME目录下的bin目录(如:ANT_HOME:,PATH:D:\apache-ant-1.9.2%ANT_HOME%\bin ...