AtCoder:Colorful Balls(思维 & 数论)

【Atcoder】AGC012 B-F简要题解 E.F 巧妙DP 阅读详情

D - Colorful Balls


Time limit : 2sec / Memory limit : 256MB

Score : 1000 points

Problem Statement

Snuke arranged N colorful balls in a row. The i-th ball from the left has color ci and weight wi.

He can rearrange the balls by performing the following two operations any number of times, in any order:

  • Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
  • Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.

How many different sequences of colors of balls can be obtained? Find the count modulo 109+7.

Constraints

  • 1≤N≤2×105
  • 1≤X,Y≤109
  • 1≤ci≤N
  • 1≤wi≤109
  • X,Y,ci,wi are all integers.

Input

Input is given from Standard Input in the following format:

N X Y
c1 w1
:
cN wN

Output

Print the answer.


Sample Input 1

Copy
4 7 3
3 2
4 3
2 1
4 4

Sample Output 1

Copy
2
  • The sequence of colors (2,4,3,4) can be obtained by swapping the positions of the first and third balls by operation 2.
  • It is also possible to swap the positions of the second and fourth balls by operation 1, but it does not affect the sequence of colors.

Sample Input 2

Copy
1 1 1
1 1

Sample Output 2

Copy
1

Sample Input 3

Copy
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21 v
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15

Sample Output 3

Copy
129729600
题意:给N个球的颜色ci和权值wi,对于相同颜色的球,权值和<=x,或者不同颜色的球权值和<=y都可以交换,不限交换次数,问组成的颜色序列数有多少种。

思路:对于不同颜色的三个球a,b,c,如果a和b能换,b和c能换,那么a和c一定能换,因为abc->acb->bca->cba,于是找到最小权值的球,建边,就变成有重复元素的组合数问题了,用乘法逆元可以解决。

# include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const LL mod = 1e9+7;
const int maxn = 2e5+3;

LL fac[maxn], inv[maxn];
int cnt, n, x, y, co[maxn], va[maxn], vis[maxn]={0}, ge[maxn]={0};
vector<int>v[maxn], tmp;
vector<pair<int, int> >r[maxn];
vector<pair<int, int> >p;

void dfs(int u)
{
    vis[u] = 1;
    ++cnt, ++ge[co[u]], tmp.push_back(co[u]);
    for(int i=0; i<v[u].size(); ++i)
    {
        int e = v[u][i];
        if(vis[e]) continue;
        dfs(e);
    }
}
int main()
{
    int c, w;
    scanf("%d%d%d",&n,&x,&y);
    cnt = 0;
    fac[0] = fac[1] = inv[0] = inv[1] = 1;
    for(LL i=2; i<=n; ++i)
    {
        fac[i] = fac[i-1]*i%mod;
        inv[i] = (mod-mod/i)*inv[mod%i]%mod;
    }
    for(int i=2; i<=n; ++i)
        inv[i] = inv[i-1]*inv[i]%mod;
    for(int i=1; i<=n; ++i)
    {
        scanf("%d%d",&c,&w);
        co[i] = c, va[i] = w;
        r[c].push_back(make_pair(w, i));
    }
    for(int i=1; i<=n; ++i)
    {
        if(r[i].size())
        {
            sort(r[i].begin(), r[i].end());
            p.push_back(r[i][0]);
            for(int j=1; j<r[i].size(); ++j)
                if(r[i][j].first+r[i][0].first <= x)
                    v[r[i][0].second].push_back(r[i][j].second),
                    v[r[i][j].second].push_back(r[i][0].second);
        }
    }
    sort(p.begin(), p.end());
    if(p.size())//用权值最小的球为中介建图。
    {
        int id = p[0].second;
        for(int i=1; i<=n; ++i)
        {
            if(co[i]==co[id] || va[i]+va[id]>y) continue;
            v[id].push_back(i), v[i].push_back(id);
        }
    }
    if(p.size()>1)//该颜色的其他球也要考虑进去。
    {
        int id = p[1].second, imin = co[p[0].second];
        for(auto it = r[imin].begin(); it!=r[imin].end(); ++it)
            if(it->first + va[id]<=y)
                v[it->second].push_back(id), v[id].push_back(it->second);
    }
    dfs(p[0].second);
    LL ans = fac[cnt];
    for(int i=0; i<tmp.size(); ++i)
    {
        int num = ge[tmp[i]];
        ans = (ans*inv[num])%mod;
        ge[tmp[i]] = 0;
    }
    printf("%lld\n",ans);
    return 0;
}



从HCI层浅析LE Audio通话建立流程 本文分析了BLE AUDIO通话协议建立的全过程。当手机来电时,系统会通过CCP EATT链路通知耳机准备通话,并断开原有音乐CIS连接。随后建立通话专用的CIG组,其参数设置(如MAX SDU SIZE=80、RTN=2)与音乐场景明显不同,更注重通话的实时性。文中详细描述了设置ISO数据路径、启用ASE、建立CIS连接等关键步骤,特别指出通话采用Conversational音频上下文类型。最后解析了ISO数据包参数含义,展示了10ms周期、32kHz采样率等通话特性参数。整个过程体现了BLE AUDIO 阅读详情

相关推荐

无GPS室内飞行:基于PX4与MID360的FAST-LIO定点悬停实战解析

本文详细解析了基于PX4飞控与大疆MID360激光雷达的无GPS室内飞行技术,重点介绍了FAST-LIO算法在定点悬停中的应用。通过硬件配置、软件环境搭建、坐标系转换等实战经验,帮助开发者解决室内定位难题,实现精准悬停与稳定飞行。

weixin_29056781的博客 265

【AtCoder】【组合数学】【模型转换】Colorful Balls(AGC012)

题意: 有n个球,每个球有两个值,一个是颜色,另一个是重量。可以进行如下的操作任意次: 1.选择两个颜色相同的球,如果这两个球的重量之和小于等于X,就交换这两个球; 2.选择两个颜色不同的球,如果这两个球的重量之和小于等于Y,就交换这两个球。 问最后能够得到的本质不同的颜色的序列有多少个。 数据范围: 1&amp;amp;amp;lt;=n,color&amp;amp;amp;lt;=10^5 其余值均&amp;amp;amp;lt;=10^5 思路: 假如说X=IN...

G20202502的博客 459

3dMax效率翻倍!用Octopus章鱼插件打造你的专属快捷菜单(附MaxScript入门指南)

本文详细介绍了如何利用Octopus插件和MaxScript脚本在3dMax中打造高效快捷菜单,显著提升三维建模与动画制作的工作效率。通过饼状菜单系统、自动化宏录制和脚本控制,用户可实现个性化工作流,节省大量操作时间。文章还提供了MaxScript入门指南,帮助开发者快速掌握这一强大工具。

weixin_30920853的博客 157

AtCoder - ABC 161 - F(数论)

2.k 是 n 的约数多次执行 k/n 后结果为 1,无余数。无余数且结果为1,则在多次执行 n/k 后结果为 1 后,再次执行一定有 n%k = 1%k = 1也成立;这个最后结果其实可以由 n%k 得出,所以如果 n%k = 1,k 成立,说明 k 满足 k 是 n-1 的因数时k成立。根据 k 是 n 的约数时的两种情况,可以按一种方法判断 k 是否成立,首先必须保证 k 是不大于 √n的约数,然后一直执行 n/k 直到 n%k!如果k ∣ N ,那么N = N / k ,否则N = N − k。

m0_64172681的博客 323

TI 实时操作系统SYS/BIOS使用总结

1:概述: SYS/BIOS 是一个可扩展的实时的操作系统。具有非常快速的响应时间(在中断和任务切换时达到较短的延迟),响应时间的确定性,强壮的抢占系统,优化的内存分配和堆栈管理(尽量少的消耗和碎片)。能够实现系统的模块化并可裁剪。 最大的特点就是:实时。 2:XDCtools: XDCtools 是SYS/BIOS引用的一种实时的软件组件技术(RTSC),它包括一些有用的工具,标准的AP

带头奋青的博客 5万+

比利时风电光伏负荷一体化数据集解析与应用

本文深度解析了由比利时输电系统运营商Elia集团提供的风电光伏负荷一体化数据集。该数据集整合了负荷、风电与光伏出力数据,并包含多时间尺度的官方预测值,时间跨度长达四年,是研究能源转型、构建电力预测模型及分析电网运行的宝贵资源。文章详细介绍了数据价值、字段含义、实战应用场景(如预测模型基准测试、风光互补性分析)以及数据处理指南,为相关领域的研究与开发提供了高质量数据基础和实践参考。

weixin_29200741的博客 431

Atcoder C - Alchemist(贪心)

题目在这 -- 题目大意是有一个数列(调料)a1,a2,a3,.............an。 然后往锅里放,没放进两个 ,然后把这个数(调料)放到数列中去,依次进行。问最后的值最大是多少? 思路:当时想的也是贪心,想的是大数被/2比小数/2浪费的多。所以从小到大排个序就出来了,然后我一直考虑精度问题(题目压根没顾及精度。。),没敢直接相加/2,是先通分,最后再除。结果爆long l...

一身清贫怎敢入繁华 786

24GHz雷达DIY呼吸监测仪:用树莓派+TI IWR6843搭建生命体征检测系统(附Python代码)

本文详细介绍了如何利用树莓派和TI IWR6843毫米波雷达模块DIY非接触式呼吸监测仪。通过硬件选型、信号处理流水线设计和实时可视化系统搭建,实现高精度的生命体征检测,特别适合医疗健康和运动监测场景。附带的Python代码帮助开发者快速复现该系统。

rl6adventurer的博客 993

AtCoder - ABC 160 - DE(贪心)

有一个有 N 个点的无向图G,相邻两点间有一条边,在顶点 X, Y 之间加一条边,总共有 N 条边。对于k从 1 到 N,求出对于每个 k,图G中满足两点最短路径为 k 的整数对数。

m0_64172681的博客 412

四旋翼无人机控制算法实战:从PID到MPC的路径跟踪

本文深入探讨了四旋翼无人机控制算法的演进路径,从基础的PID控制到高级的MPC算法,详细解析了各类算法的原理、实现技巧及适用场景。通过实战案例对比分析,为开发者提供从算法选型到参数调优的全方位指导,助力提升无人机飞行控制的精度与稳定性。

weixin_29090917的博客 245

轮式并联五连杆下肢机器人运动控制:从建模到强化学习仿真训练

本文提出了一种基于强化学习的轮式并联五连杆下肢机器人运动控制方法。首先建立了机器人的运动学和动力学模型,推导了正逆解公式,并构建了URDF模型。随后在PyBullet仿真环境中搭建了包含复杂地形的训练场景,设计了基于PPO算法的端到端控制策略,包含状态空间、动作空间和奖励函数的详细设计。通过多组仿真实验验证了该方法在台阶攀爬等任务中的有效性,为轮腿机器人运动控制提供了完整的可复现技术方案。

huanghm88的专栏 354

【好题总结】atcoder好题选做

学习ShichengXiao’s的笔记 一下是简单的小结和感想 ARC 098F 找性质,定经过顺序,然后DP 注意要把多的贡献的定义搞清楚。因为知道了选点的先后顺序,可以dfs递归其他联通块。然而是不能直接暴力dfs的,因为这不是点分,每次找根不是重心,直接dfs会TLE。 还要注意每个联通块的根不是直接和上一层根相连的点。 可以倒过来做,每次合并,用并查集维护,更加好写。 根据定义,每个联通块...

执子之手,与子偕老 1971

ArcGIS Pro 3.4 二次开发 - 布局

本文介绍了在ArcGIS Pro SDK 3.4和.NET 8环境下操作布局工程项的相关方法。主要内容包括:引用布局工程项和关联布局,在新视图中打开或激活已有布局视图,引用活动布局视图,导入/移除布局工程项,创建基本布局或带参考线的自定义布局,修改布局页面尺寸,以及创建圆形图形元素等操作。重点演示了如何通过CIM(Core Infrastructure Model)进行高级布局配置,并详细说明了圆形图形元素的创建过程,包括几何构建、符号设置和图形生成。所有涉及UI线程的操作都遵循ArcGIS Pro SDK

Winemonk 800

AtCoder Grand Contest 012 D:Colorful Balls

题目传送门:https://agc012.contest.atcoder.jp/tasks/agc012_d 题目翻译 给你一排一共\(N\)个球,每个球有一个颜色\(c_i\)和一个重量\(w_i\),如果两个球颜色相同,重量相加不超过\(x\)那我就可以交换这俩个球的位置。如果两个球颜色不同,重量相加不超过\(y\)那我也可以交换这俩球的位置。你可以随心所欲的交换或者不交换,求最后颜...

aga28832的博客 176

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

[AT2364] [agc012_d] Colorful Balls

题目链接 AtCoder:https://agc012.contest.atcoder.jp/tasks/agc012_d 洛谷:https://www.luogu.org/problemnew/show/AT2364 Solution 首先很容易得到一个\(O(n^2)\)的做法: 两个可以\(\rm swap\)的点连边,那么答案就是联通块大小的阶乘之积除以颜色相同的阶乘之积。 注意到如果按题...

weixin_30337251的博客 163

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Atcoder AGC012D:Colorful Balls

传送门 题解: 容易发现交换具有传递性。所以答案为每个联通块方案之积。 进一步发现只需要与每种颜色最小的连边,之后统计出每个联通块的方案数为: n!Πai!n!Πai!\frac{n!}{\Pi a_i!} #include &amp;lt;bits/stdc++.h&amp;gt; using namespace std; typedef long long LL; const int RLEN=...

DZYO的博客 379

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = &quot;R. B. Palm&quot;, title = &quot;Prediction as a candidate for learning deep hierarchical models of data&quot;, year = &quot;2012&quot;,}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er&lt;0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free &quot;Bitdeli Badge&quot;)

AGC 012 D - Colorful Balls

题面在这里! 为什么atcoder都是神仙题啊qwq 首先发现如果要让 x,y 互换位置的话,要么通过他们直接换 (也就是x和y满足两种操作之一),要么间接换,通过一些其他的元素形如 x可以和 a[1]换,a[1]可以和a[2]换。。。a[k-1]可以和a[k]换,a[k]可以和y换,x就可以和y换啦。 所以就可以建模到一个无向图上,发现一个联通块内的元素之间都...

weixin_30426065的博客 206

AtCoder Grand Contest 012 D Colorful Balls

题意: 有N个球排成一行,第i个球颜色为ci, 权为wi, 如果两个同色球权值和 &lt;= X 则它们可以交换; 如果两个异色球权值和 &lt;= Y 则它们可以交换;不限制交换次数,求能到达的颜色序列有多少种。 1&lt;=n&lt;=2e5;1&lt;=x,y&lt;=1e9;1&lt;=ci&lt;=n;1&lt;=wi&lt;=1e9 分析: 我们可以通过n^2的枚举,来枚举两...

weixin_30379973的博客 129

AtCoder Grand Contest 016 C - +/- Rectangle

题目传送门:https://agc016.contest.atcoder.jp/tasks/agc016_c 题目大意: 给定整数\(H,W,h,w\),你需要判断是否存在满足如下条件的矩阵,如果存在,则输出任意一种可能的方案 矩阵是\(H\)行\(W\)列 矩阵的每个元素的权值在\([-10^9,10^9]\)之间 矩阵的所有元素权值和为正 任意大小为\(h×w\)的子矩阵的元素权值和为负 ...

weixin_30645617的博客 187

常用算法代码模板与题单 | 0 - 模拟(更新于2026.10.7)

这篇文档其实是我自己学习路上的一份“复习笔记”。之前看了不少教程,零零散散记了一堆代码片段和小技巧,时间久了就容易忘,翻起来也麻烦。所以干脆花时间整理了一下,把常用的模板、容易踩的坑、还有一些个人觉得挺实用的小技巧都归到了一起。 如果你也在学类似的东西,或许能帮你省下一些翻找的时间;如果有哪里写得不清楚或不对,也欢迎随时指正交流。 希望这份整理也能对你有一点点帮助~ ✨

团爸讲算法 1478

ATcoder 2000 Leftmost Ball

Problem Statement Snuke loves colorful balls. He has a total ofN×Kballs,Kin each of his favoriteNcolors. The colors are numbered1throughN. He will arrange all of the balls in a row from ...

weixin_30883311的博客 89

AT2000 Leftmost Ball

atcoder 一道小清新dp题 我们设\(f[i][j]\)表示当前放了\(i\)个白球和\(j\)种其他颜色的球\((j&lt;=i)\) 发现我们每次可以多放一个白球或者多放一种其他颜色的球 多放一个白球就是\(f[i-1][j]\) 多放一种其他颜色的球的时候,我们需要钦点一个球放在当前第一个位置上,否则会重复计算,所以就是\(f[i][j-1]*(n-j+1)*\binom{n...

weixin_30670925的博客 138

常用算法代码模板与题单 | A - 基础算法(更新于2026.10.7)

这篇文档其实是我自己学习路上的一份“复习笔记”。之前看了不少教程,零零散散记了一堆代码片段和小技巧,时间久了就容易忘,翻起来也麻烦。所以干脆花时间整理了一下,把常用的模板、容易踩的坑、还有一些个人觉得挺实用的小技巧都归到了一起。 如果你也在学类似的东西,或许能帮你省下一些翻找的时间;如果有哪里写得不清楚或不对,也欢迎随时指正交流。 希望这份整理也能对你有一点点帮助~ ✨

团爸讲算法 810

常用算法代码模板与题单 | D - 图论(更新于2026.10.7)

这篇文档其实是我自己学习路上的一份“复习笔记”。之前看了不少教程,零零散散记了一堆代码片段和小技巧,时间久了就容易忘,翻起来也麻烦。所以干脆花时间整理了一下,把常用的模板、容易踩的坑、还有一些个人觉得挺实用的小技巧都归到了一起。 如果你也在学类似的东西,或许能帮你省下一些翻找的时间;如果有哪里写得不清楚或不对,也欢迎随时指正交流。 希望这份整理也能对你有一点点帮助~ ✨

团爸讲算法 795
上一篇: CFgym: Laying Cables(单调栈)
下一篇: CF799D:Field expansion(dp)
junior19
博客等级 码龄10年 118粉丝 615原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值