核心内容摘要
探索NVIDIA显卡性能调校:解锁GPU参数优化的隐藏潜力
D. Taiga’s Carry ChainsMiracles don’t happen to those who just wait.— Toradora!After classes at Ohashi High School, Ryuuji hands Taiga a positive integern nnand sets a simple challenge.They will play for exactlyk kkmoves. In a single move, Taiga chooses a non-negative integerℓ \ellℓand setsn ← n 2 ℓ n \gets n 2^{\ell}n←n2ℓ.Ryuuji defines the score of one move as the number of binary carries that occur when adding2 ℓ 2^{\ell}2ℓto the current number in base2
The total score is the sum of score over allk kkmoves.Taiga wants the total score to be as large as possible afterk kkmoves. What is the maximum total score she can achieve?大桥高中放学后龙寺递给大河一个正整数n并设定了一个简单的挑战。
他们将精确执行 k 步。
在一次移动中Taiga 选择一个非负整数 ℓ 并设置n ← n 2 ℓ n \gets n 2^{\ell}n←n2ℓ.Ryuuji 将一步棋的分数定义为将 2ℓ 添加到基数 2 中的当前数字时发生的二进制进位数。
总得分是所有 k 动作的得分总和。
大河希望 k 移动后总得分尽可能大。
她能达到的最高总分是多少题解可以发现一些性质就是如果步骤足够大可以把所有的二进制中的 0 全部填写为 1这就是一个贪心上的最优解但是我们往往没有那么大的步骤数则此时可以有一些转化。
下面介绍两种思路直接把所有的间隔连续的 0 的块进行枚举我们可以发现int范围内二进制位数最多 32 位则间隔不会超过 162 16 2^{16}216也就是10 5 10^5105的枚举数量枚举一下会填写那些块以及不会填写哪些块就是一个状压枚举之后瞎搞搞就行。
大致就是先填充填充完毕后对于剩下的块排序把多余的 k 连接上去可以证明这里面存在最优解主打暴力。
voidsolve(){intn,k;cinnk;intB__lg(n)1,zB-__popcount(n);if(kz){coutk-zB-1endl;return;}vectorintg,num;for(inti__lg(n);i0;i--){if((ni
1)
{intji-1;while(j0((nj
1)
)j--;j;g.push_back(i-j
;num.push_back((1LL(i
)-1-((1LLj)-
);ij;}}intans0LL;intM1LL(int)g.size();for(intmask0;maskM;mask){intmn,co0LL;for(intbit0;bit(int)g.size();bit){if(maskbit
{m|num[bit];cog[bit];if(cok){break;}}}if(cok)continue;intnumk-co,res0;vectorinttem;for(inti__lg(m);i0;i--){if(mi
{intji-1;while(j0(mj
)j--;j;tem.push_back(i-j
;ij;}}sort(range(tem),greaterint());for(inti0;imin((int)tem.size(),num);i){restem[i];}resmax(0LL,num-(int)tem.size());ansmax(ans,res);}coutansendl;}第二种思路就是 DP了题解里面写了再对于官方题解代码做一些解释#includebits/stdc.h#defineintlonglongusingnamespacestd;constintinf1e97;constintmxb64,mxk32;intdp[mxb2][mxk2][2];voidMin(intx,inty){xmin(x,y);}voidsolve(){intn,k;cinnk;intpc__builtin_popcount(n);if(n
{coutmax(0ll,k-
\n;return;}if(k
{coutkpc-1\n;return;}for(inti0;imxb;i)for(intj0;jk;j)dp[i][j][0]dp[i][j][1]inf;dp[0][0][0]0;for(inti0;imxb;i){intni(ni)1ll;for(intu0;uk;u)for(intc0;c1;c){intcurdp[i][u][c];if(curinf)continue;{intsumnic,bitsum1,ncsum1;Min(dp[i1][u][nc],curbit);}if(u1k){intsumni1c,bitsum1,ncsum1;Min(dp[i1][u1][nc],curbit);}}}intbstinf;for(intu0;uk;u)for(intc0;c1;c){intvaldp[mxb][u][c];if(valinf)Min(bst,valc);}intanskpc-bst;coutans\n;}signedmain(){ios_base::sync_with_stdio(false);cin.tie(
,cout.tie(
;intT;cinT;for(;T--;)solve();return0;}这里 dp 表示最小的 1 的个数从最低位 - 最高位进行转移d p [ i ] [ j ] [ c ] dp[i][j][c]dp[i][j][c]表示从低位开始处理到了第 i 位进行了 j 次操作且当前位置有没有从上一位进行进位的最小1的个数。
sum 表示当前位考虑进位考虑 1 之后的值然后 bit 表示本位最后是啥nc 表示进位没有。
然后就转移就行了。
E. Shiro’s Mirror Dueltime limit per test: 3 secondsmemory limit per test: 256 megabytesinput: standard inputoutput: standard outputThere’s no such thing as luck in this world. The victor is decided before the game even starts.— No Game No LifeThis is an interactive problem.One day, Sora and Shiro feel bored again, so they decide to settle it with a game.At the beginning, Sora gives Shiro a permutation∗ ^{\text{∗}}∗p 1 , p 2 , … , p n p_1,p_2,\ldots,p_np1,p2,…,pnof lengthn nn. In each operation, Shiro may select two distinct indicesx xxandy yy(1 ≤ x ≠ y ≤ n 1\le x\ne y\le n1≤xy≤n). Then Sora flips a fair coin:With probability
5
0.
5
5, Sora swapsp x p_xpxandp y p_ypy;With probability
5
0.
5