2018.10.6模拟考试
感动...某毒瘤出题人这次出的题竟然可做...
T1 这题乍一看就知道是一道数学公式题...自己仔细推推就能推出来...
已知(x+1)^n=C(n,0)* x ^n+C(n,1)* x ^(n-1)+...+C(n,n)* x ^0
易知(x+2)^n=C(n,0)*(x+1)^n+C(n,1)*(x+1)^(n-1)+...+C(n,n)*(x+1)^0
所以可以分别维护sum[x^0]~sum[x^k],插入时按照(x-1)插入,修改时将sum从x^n到x^0分别维护即可。
#include<algorithm>//STL通用算法 #include<bitset>//STL位集容器 #include<cctype> #include<cmath> #include<complex> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<deque>//STL双端队列容器 #include<list>//STL线性列表容器 #include<map>//STL映射容器 #include<iostream> #include<queue>//STL队列容器 #include<set>//STL集合容器 #include<stack>//STL堆栈容器 #include<utility>//STL通用模板类 #include<vector>//STL动态数组容器 #define INF 0x3f3f3f3f #define ll long long #define MOD 1000000007 using namespace std; ll n,m,sum[51]; ll yh[51][51]={ {1}, {1,1}, {1,2,1}, {1,3,3,1}, {1,4,6,4,1}, {1,5,10,10,5,1}, {1,6,15,20,15,6,1}, {1,7,21,35,35,21,7,1}, {1,8,28,56,70,56,28,8,1}, {1,9,36,84,126,126,84,36,9,1}, {1,10,45,120,210,252,210,120,45,10,1}, {1,11,55,165,330,462,462,330,165,55,11,1}, {1,12,66,220,495,792,924,792,495,220,66,12,1}, {1,13,78,286,715,1287,1716,1716,1287,715,286,78,13,1}, {1,14,91,364,1001,2002,3003,3432,3003,2002,1001,364,91,14,1}, {1,15,105,455,1365,3003,5005,6435,6435,5005,3003,1365,455,105,15,1}, {1,16,120,560,1820,4368,8008,11440,12870,11440,8008,4368,1820,560,120,16,1}, {1,17,136,680,2380,6188,12376,19448,24310,24310,19448,12376,6188,2380,680,136,17,1}, {1,18,153,816,3060,8568,18564,31824,43758,48620,43758,31824,18564,8568,3060,816,153,18,1}, {1,19,171,969,3876,11628,27132,50388,75582,92378,92378,75582,50388,27132,11628,3876,969,171,19,1}, {1,20,190,1140,4845,15504,38760,77520,125970,167960,184756,167960,125970,77520,38760,15504,4845,1140,190,20,1}, {1,21,210,1330,5985,20349,54264,116280,203490,293930,352716,352716,293930,203490,116280,54264,20349,5985,1330,210,21,1}, {1,22,231,1540,7315,26334,74613,170544,319770,497420,646646,705432,646646,497420,319770,170544,74613,26334,7315,1540,231,22,1}, {1,23,253,1771,8855,33649,100947,245157,490314,817190,1144066,1352078,1352078,1144066,817190,490314,245157,100947,33649,8855,1771,253,23,1}, {1,24,276,2024,10626,42504,134596,346104,735471,1307504,1961256,2496144,2704156,2496144,1961256,1307504,735471,346104,134596,42504,10626,2024,276,24,1}, {1,25,300,2300,12650,53130,177100,480700,1081575,2042975,3268760,4457400,5200300,5200300,4457400,3268760,2042975,1081575,480700,177100,53130,12650,2300,300,25,1}, {1,26,325,2600,14950,65780,230230,657800,1562275,3124550,5311735,7726160,9657700,10400600,9657700,7726160,5311735,3124550,1562275,657800,230230,65780,14950,2600,325,26,1}, {1,27,351,2925,17550,80730,296010,888030,2220075,4686825,8436285,13037895,17383860,20058300,20058300,17383860,13037895,8436285,4686825,2220075,888030,296010,80730,17550,2925,351,27,1}, {1,28,378,3276,20475,98280,376740,1184040,3108105,6906900,13123110,21474180,30421755,37442160,40116600,37442160,30421755,21474180,13123110,6906900,3108105,1184040,376740,98280,20475,3276,378,28,1}, {1,29,406,3654,23751,118755,475020,1560780,4292145,10015005,20030010,34597290,51895935,67863915,77558760,77558760,67863915,51895935,34597290,20030010,10015005,4292145,1560780,475020,118755,23751,3654,406,29,1}, {1,30,435,4060,27405,142506,593775,2035800,5852925,14307150,30045015,54627300,86493225,119759850,145422675,155117520,145422675,119759850,86493225,54627300,30045015,14307150,5852925,2035800,593775,142506,27405,4060,435,30,1}, {1,31,465,4495,31465,169911,736281,2629575,7888725,20160075,44352165,84672315,141120525,206253075,265182525,300540195,300540195,265182525,206253075,141120525,84672315,44352165,20160075,7888725,2629575,736281,169911,31465,4495,465,31,1}, {1,32,496,4960,35960,201376,906192,3365856,10518300,28048800,64512240,129024480,225792840,347373600,471435600,565722720,601080390,565722720,471435600,347373600,225792840,129024480,64512240,28048800,10518300,3365856,906192,201376,35960,4960,496,32,1}, {1,33,528,5456,40920,237336,1107568,4272048,13884156,38567100,92561040,193536720,354817320,573166440,818809200,37158313,166803103,166803103,37158313,818809200,573166440,354817320,193536720,92561040,38567100,13884156,4272048,1107568,237336,40920,5456,528,33,1}, {1,34,561,5984,46376,278256,1344904,5379616,18156204,52451256,131128140,286097760,548354040,927983760,391975633,855967513,203961416,333606206,203961416,855967513,391975633,927983760,548354040,286097760,131128140,52451256,18156204,5379616,1344904,278256,46376,5984,561,34,1}, {1,35,595,6545,52360,324632,1623160,6724520,23535820,70607460,183579396,417225900,834451800,476337793,319959386,247943139,59928922,537567622,537567622,59928922,247943139,319959386,476337793,834451800,417225900,183579396,70607460,23535820,6724520,1623160,324632,52360,6545,595,35,1}, {1,36,630,7140,58905,376992,1947792,8347680,30260340,94143280,254186856,600805296,251677693,310789586,796297179,567902525,307872061,597496544,75135237,597496544,307872061,567902525,796297179,310789586,251677693,600805296,254186856,94143280,30260340,8347680,1947792,376992,58905,7140,630,36,1}, {1,37,666,7770,66045,435897,2324784,10295472,38608020,124403620,348330136,854992152,852482989,562467279,107086758,364199697,875774586,905368605,672631781,672631781,905368605,875774586,364199697,107086758,562467279,852482989,854992152,348330136,124403620,38608020,10295472,2324784,435897,66045,7770,666,37,1}, {1,38,703,8436,73815,501942,2760681,12620256,48903492,163011640,472733756,203322281,707475134,414950261,669554037,471286455,239974276,781143184,578000379,345263555,578000379,781143184,239974276,471286455,669554037,414950261,707475134,203322281,472733756,163011640,48903492,12620256,2760681,501942,73815,8436,703,38,1}, {1,39,741,9139,82251,575757,3262623,15380937,61523748,211915132,635745396,676056037,910797415,122425388,84504291,140840485,711260731,21117453,359143556,923263934,923263934,359143556,21117453,711260731,140840485,84504291,122425388,910797415,676056037,635745396,211915132,61523748,15380937,3262623,575757,82251,9139,741,39,1}, {1,40,780,9880,91390,658008,3838380,18643560,76904685,273438880,847660528,311801426,586853445,33222796,206929679,225344776,852101216,732378184,380261009,282407483,846527861,282407483,380261009,732378184,852101216,225344776,206929679,33222796,586853445,311801426,847660528,273438880,76904685,18643560,3838380,658008,91390,9880,780,40,1}, {1,41,820,10660,101270,749398,4496388,22481940,95548245,350343565,121099401,159461947,898654871,620076241,240152475,432274455,77445985,584479393,112639186,662668492,128935337,128935337,662668492,112639186,584479393,77445985,432274455,240152475,620076241,898654871,159461947,121099401,350343565,95548245,22481940,4496388,749398,101270,10660,820,41,1}, {1,42,861,11480,111930,850668,5245786,26978328,118030185,445891810,471442966,280561348,58116811,518731105,860228716,672426930,509720440,661925378,697118579,775307678,791603829,257870674,791603829,775307678,697118579,661925378,509720440,672426930,860228716,518731105,58116811,280561348,471442966,445891810,118030185,26978328,5245786,850668,111930,11480,861,42,1}, {1,43,903,12341,123410,962598,6096454,32224114,145008513,563921995,917334776,752004314,338678159,576847916,378959814,532655639,182147363,171645811,359043950,472426250,566911500,49474496,49474496,566911500,472426250,359043950,171645811,182147363,532655639,378959814,576847916,338678159,752004314,917334776,563921995,145008513,32224114,6096454,962598,123410,12341,903,43,1}, {1,44,946,13244,135751,1086008,7059052,38320568,177232627,708930508,481256764,669339083,90682466,915526075,955807730,911615453,714803002,353793174,530689761,831470200,39337743,616385996,98948992,616385996,39337743,831470200,530689761,353793174,714803002,911615453,955807730,915526075,90682466,669339083,481256764,708930508,177232627,38320568,7059052,1086008,135751,13244,946,44,1}, {1,45,990,14190,148995,1221759,8145060,45379620,215553195,886163135,190187265,150595840,760021549,6208534,871333798,867423176,626418448,68596169,884482935,362159954,870807943,655723739,715334988,715334988,655723739,870807943,362159954,884482935,68596169,626418448,867423176,871333798,6208534,760021549,150595840,190187265,886163135,215553195,45379620,8145060,1221759,148995,14190,990,45,1}, {1,46,1035,15180,163185,1370754,9366819,53524680,260932815,101716323,76350393,340783105,910617389,766230083,877542332,738756967,493841617,695014617,953079104,246642882,232967890,526531675,371058720,430669969,371058720,526531675,232967890,246642882,953079104,695014617,493841617,738756967,877542332,766230083,910617389,340783105,76350393,101716323,260932815,53524680,9366819,1370754,163185,15180,1035,46,1}, {1,47,1081,16215,178365,1533939,10737573,62891499,314457495,362649138,178066716,417133498,251400487,676847465,643772408,616299292,232598577,188856227,648093714,199721979,479610772,759499565,897590395,801728689,801728689,897590395,759499565,479610772,199721979,648093714,188856227,232598577,616299292,643772408,676847465,251400487,417133498,178066716,362649138,314457495,62891499,10737573,1533939,178365,16215,1081,47,1}, {1,48,1128,17296,194580,1712304,12271512,73629072,377348994,677106633,540715854,595200214,668533985,928247952,320619866,260071693,848897869,421454804,836949941,847815693,679332751,239110330,657089953,699319077,603457371,699319077,657089953,239110330,679332751,847815693,836949941,421454804,848897869,260071693,320619866,928247952,668533985,595200214,540715854,677106633,377348994,73629072,12271512,1712304,194580,17296,1128,48,1}, {1,49,1176,18424,211876,1906884,13983816,85900584,450978066,54455620,217822480,135916061,263734192,596781930,248867811,580691559,108969555,270352666,258404738,684765627,527148437,918443081,896200283,356409023,302776441,302776441,356409023,896200283,918443081,527148437,684765627,258404738,270352666,108969555,580691559,248867811,596781930,263734192,135916061,217822480,54455620,450978066,85900584,13983816,1906884,211876,18424,1176,49,1}, {1,50,1225,19600,230300,2118760,15890700,99884400,536878650,505433686,272278100,353738541,399650253,860516122,845649741,829559370,689661114,379322221,528757404,943170365,211914057,445591511,814643357,252609299,659185464,605552882,659185464,252609299,814643357,445591511,211914057,943170365,528757404,379322221,689661114,829559370,845649741,860516122,399650253,353738541,272278100,505433686,536878650,99884400,15890700,2118760,230300,19600,1225,50,1} }; void query() { ll ans=0; for(ll i=0;i<=m;i++) (ans+=yh[m][i]*sum[i]%MOD)%=MOD; printf("%lld\n",ans); } int main() { freopen("set.in","r",stdin); freopen("set.out","w",stdout); scanf("%lld%lld",&n,&m); for(ll i=1;i<=n;i++) { ll u;scanf("%lld",&u); if(u==0) { ll v;scanf("%lld",&v); v--;ll tmp=1; for(ll i=0;i<=m;i++) (sum[i]+=tmp)%=MOD,(tmp*=v)%=MOD; query(); } if(u==1) { for(ll i=m;i;i--) for(ll j=i-1;j>=0;j--) (sum[i]+=sum[j]*yh[i][j]%MOD)%=MOD; query(); } } return 0; }
(那个三角是杨辉三角...博主懒得打计算式了)
然而这样做的时间复杂度是O(m*k*k),只能拿70分。
有一个显然的优化是把所有数插入时按照(x-cnt)插入,其中cnt表示到目前为止已修改的次数。
这样就能把所有数的修改标记统一,可以减去一个k。
#include<algorithm>//STL通用算法 #include<bitset>//STL位集容器 #include<cctype> #include<cmath> #include<complex> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<deque>//STL双端队列容器 #include<list>//STL线性列表容器 #include<map>//STL映射容器 #include<iostream> #include<queue>//STL队列容器 #include<set>//STL集合容器 #include<stack>//STL堆栈容器 #include<utility>//STL通用模板类 #include<vector>//STL动态数组容器 #define INF 0x3f3f3f3f #define ll long long #define MOD 1000000007 using namespace std; ll n,k,cnt,fac[51],inv[51],sum[51]; ll qpow(ll x,ll y) { ll tmp=1; while(y) { if(y&1) (tmp*=x)%=MOD; (x*=x)%=MOD,y/=2; } return tmp; } ll C(ll x,ll y) { if(x<y) return 0; return fac[x]*inv[y]%MOD*inv[x-y]%MOD; } int main() { freopen("set.in","r",stdin); freopen("set.out","w",stdout); scanf("%lld%lld",&n,&k); fac[0]=1; for(ll i=1;i<=k;i++) fac[i]=fac[i-1]*i%MOD, inv[k]=qpow(fac[k],MOD-2); for(ll i=k-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%MOD; for(ll i=1;i<=n;i++) { ll u;scanf("%lld",&u); if(!u) { ll v;scanf("%lld",&v); (v-=cnt-MOD)%=MOD; ll tmp=1; for(ll j=0;j<=k;j++) (sum[j]+=tmp)%=MOD,(tmp*=v)%=MOD; } else cnt++; ll tmp=1,ans=0; for(ll j=k;j>=0;j--) { (ans+=(tmp*(C(k,j)*sum[j]%MOD)%MOD))%=MOD; (tmp*=cnt)%=MOD; } printf("%lld\n",ans); } return 0; }
T2 其实这道题相对来说是最水的...
设x从小到大排列,sum为小于等于k的所有数的前缀和,发现可把sum分为3类:
1.sum<k 这类数字对当前k的答案是必定没有贡献的,所以可以不看。
2.k<sum<2k 这类数字直接满足条件。
3.sum>2k 这类数字通过减少一些最小的数是会对答案有贡献的。
为什么一定有贡献?因为sum里只包含小于等于k的数,这说明sum无法一次性从>2k跳到<k。
对于第2类,我们知道,对于一个sum,[ceil(sum/2),sum]必定满足条件。
对于第3类,我们知道,对于一个sum,[ceil(k/2),ceil(num/2)]必定满足条件。
因此,只需枚举n遍sum,分别计算区间,取交集即可。
#include<algorithm>//STL通用算法 #include<bitset>//STL位集容器 #include<cctype> #include<cmath> #include<complex> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<deque>//STL双端队列容器 #include<list>//STL线性列表容器 #include<map>//STL映射容器 #include<iostream> #include<queue>//STL队列容器 #include<set>//STL集合容器 #include<stack>//STL堆栈容器 #include<utility>//STL通用模板类 #include<vector>//STL动态数组容器 #define INF 0x3f3f3f3f #define ll long long using namespace std; ll n,sum,lst,ans,num[100001]; int main() { freopen("sum.in", "r", stdin); freopen("sum.out", "w", stdout); scanf("%lld",&n); for(ll i=1;i<=n;i++) scanf("%lld",&num[i]); sort(num+1,num+1+n); for(ll i=1;i<=n;i++) { ll now=num[i];sum+=now; while(num[i+1]==now) sum+=now,i++; ans+=sum-max(lst,(now+1)/2)+(lst<(now+1)/2); lst=sum; } printf("%lld\n",ans); return 0; }
T3 这是一道最不像博弈论的博弈论...
显然,当位置i有超过2^i个僵尸时AI必胜。
发现正着算并不好算,考虑计算AI自爆的情况。
发现只要使所有满足num[i]>=2^i的位置上的僵尸分配到两行后有一行僵尸的个数<2^(i-1)即可。
如,在第2列第1行有5个僵尸,那么第1,2行上的僵尸个数分别满足(4,1)(1,4)(5,0)时AI即自爆。
用总种类数减去,再乘上无关僵尸(即那些不满足num[i]>=2^i的位置上的僵尸)的分配情况数即可。
然后你就得到了一个0分的优秀算法。(没错博主就是这样的QAQ)
以下是一组自爆数据:
Input: 8 1 1 2 1 2 3 3 1 Output: 236
你会发现在这组数据中,第1列有4个僵尸,第2列有2个,第3列有2个。
然后依照以上算法,第2,3列的僵尸都是无关僵尸,算出总情况数与第一列的合法情况数相乘即可。
但是,你没发现什么端倪吗?
你发现,就算AI自暴自弃,把第1列的僵尸全部抛弃,然而它只要把第2列的僵尸全数保留,第2列的僵尸就走到了第1
列,其数量正好满足>=2^1的条件。就算AI偏要再自爆一次,第3列的僵尸也会补到第1列,照样满足>=2^1的条件。
(当然,如果AI是Kizuna AI酱就莓办法了2333)
所以正解是?
由于博主太蒟蒻,没能理解所谓背包的含义...在这里贴上某大佬的博客链接,在这里有详细的正解解释。
以下是std:(悄悄说一句,std是真的丑...)
#include <stdio.h> #include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <string.h> #define rep(i, x, y) for (int i = (x), _ = (y); i < _; ++i) #define down(i, x, y) for (int i = (x) - 1, _ = (y); i >= _; --i) #define fi first #define se second #define mp(x, y) make_pair(x, y) #define pb(x) push_back(x) #define bin(x) (1 << (x)) #define SZ(x) int((x).size()) //#define LX_JUDGE using namespace std; typedef pair<int, int> pii; typedef vector<int> Vi; typedef long long ll; template<typename T> inline bool upmax(T &x, T y) { return x < y ? (x = y, 1) : 0; } template<typename T> inline bool upmin(T &x, T y) { return x > y ? (x = y, 1) : 0; } namespace MATH_CAL { const int mod = 1e9 + 7; inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } inline int mul(int a, int b) { return (ll) a * b % mod; } inline void Add(int &a, int b) { (a += b) >= mod ? a -= mod : 0; } inline void Sub(int &a, int b) { (a -= b) < 0 ? a += mod : 0; } inline int qpow(int x, int n) { int r = 1; for ( ; n; n /= 2, x = mul(x, x)) if (n & 1) r = mul(r, x); return r; } inline int mod_inv(int x) { return qpow(x, mod - 2); } } using namespace MATH_CAL; const int MAX_N = 2005; void WORK() { int N; static int a[MAX_N], f[MAX_N]; memset(f, 0, sizeof(f)); scanf("%d", &N); rep (i, 0, N) scanf("%d", &a[i]); sort(a, a + N); f[0] = 1; int now = a[N - 1], M = 0; down (i, N, 0) { int v = a[i]; int l = 1; while (now != v) { now--; l *= 2; // if (l > M) { // now = v; // break ; // } } if (l > 1) { rep (i, 0, M / l + 1) { int cnt = 0; rep (j, i * l, min((i + 1) * l, M + 1)) { Add(cnt, f[j]); f[j] = 0; } f[i] = cnt; } M /= l; } down (j, M + 1, 0) Add(f[j + 1], f[j]); //手动推C(x,y) M++; } int t = 1; while (now > 1) { t *= 2; upmin(t, M + 1); now--; } int ans = 0; rep (j, 0, t) Add(ans,f[j]); printf("%d\n", mul(2, sub(qpow(2, N - 1), ans))); } int main() { #ifdef LX_JUDGE freopen(".in", "r", stdin); #endif // freopen("pvz.in", "r", stdin); // freopen("pvz.out", "w", stdout); int T; scanf("%d", &T); while (T--) WORK(); return 0; }