首页 > 其他分享 >CF1866D Digital Wallet

CF1866D Digital Wallet

时间:2024-07-31 15:51:06浏览次数:6  
标签:CF1866D int Wallet num read 一列 Digital 区间 getchar

传送门

题意

给你一个\(n*m\)正数矩阵,(\(n\le 10, m \le 1e5, k\le10\)), 有一个\(n*k\)的窗口在矩阵中,\(k\leq m\), 这个窗口一开始在最左边,你可以从窗口覆盖的范围里取出一个数加入答案并置零, 接下来窗口会每次向右滑动一格,每次滑动完你都可以取一个数加入答案并置零, 直到窗口无法滑动时停止,问最大答案。

题解

简略题解: 我们考虑所有数是同时取的,对于每一列我们完全可以从大到小排序,这一列如果取了\(x\)个数,那一定是前\(x\)大的数。

于是问题转化为有若干个区间,每个区间可以选择它覆盖的其中一列,让这一列选的个数加一,这时我们就可以开始dp了,我们记录\(f_{i,j}\)表示当前到第i行,前\(i-1\)行(每个区间我们假设是在它覆盖的第一列产生的)的区间,有一些用了, 还剩下\(j\)个没有用,对于每一行,这一列有可能产生一个新的区间,也有可能不会(窗口不会滑动之后的每一列虽然可以选,但只能用之前剩下的区间) , 对于每一列, 它的转移只有选几个而已, 每次我选一个数,我一定用的是当前剩下的区间里最左边的区间,因为如果最左边区间能覆盖的点,右边的区间一定也能覆盖, 左边更劣,先把劣区间用了肯定更优。

这个dp能成立的关键在于, 每次用的一定是最左边的区间, 如果之前剩下了\(x\)个区间, 那也一定是当前一格之前最右边的\(x\)个区间。这样我们就不需要记录剩下区间的位置,从而计算哪些区间还能用,而那些区间已经超出范围了, 具体的判断就不多讲了,可看代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long 
using namespace std;

int read(){
	int num=0, flag=1; char c=getchar();
	while(!isdigit(c) && c!='-') c=getchar();
	if(c == '-') flag=-1, c=getchar();
	while(isdigit(c)) num=num*10+c-'0', c=getchar();
	return num*flag;
}

const int N = 20;
const int M = 1e5+1000;
int n, m, k;
int a[M][N];
int sum[M][N];
ll f[M][N];
	
int main(){
	n=read(), m=read(), k=read();
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			a[j][i]=read();
		}
	}
	
	for(int i=1; i<=m; i++){
		sort(a[i]+1, a[i]+1+n, [](int i, int j) {
			return i > j;
		});
		for(int j=1; j<=n; j++) sum[i][j] = sum[i][j-1]+a[i][j];
	}
	
	f[m][0]=0, f[m][1]=sum[m][1];
	if(k == 1) f[m][0] = sum[m][1];
	for(int i=m-1; i>=1; i--){
		for(int j=0; j<=k-1; j++){
			int x = j; 
			if(i <= m-k+1) x++;
			for(int l=0; l<=x; l++){
				f[i][j] = max(f[i][j], sum[i][l] + f[i+1][min(x-l, min(k-1, m-k+1-(i+1-k)))]);
			}
		}
	}
	
	printf("%lld\n", f[1][0]);
	
	return 0;
} 

标签:CF1866D,int,Wallet,num,read,一列,Digital,区间,getchar
From: https://www.cnblogs.com/ltdjcoder/p/18334738

相关文章

  • 使用 DigitalOcean Spaces 在 Django 应用程序中初始化 boto3 会话时出错
    当我尝试将Django应用程序配置为使用DigitalOceanSpaces处理静态文件和媒体文件时,我遇到了问题。这是我的settings.py文件的相关部分:importboto3frombotocore.exceptionsimportNoCredentialsError,PartialCredentialsErrorfrombotocore.clientimportCo......
  • 模拟增益(Analog Gain)、数字增益(Digital Gain)
    在WebRTC中,模拟增益和数字增益是两种增强音频信号的技术,它们在确保通话质量中扮演着重要角色。下面我将详细解释这两种增益的概念及其作用。模拟增益(AnalogGain)模拟增益是在模拟信号处理阶段调整信号强度的过程。模拟增益通常在音频信号被转换为数字信号之前,在麦克风放大器级别......
  • Ton 区块链 Minter与Wallet的合约部署关联细节
    作者:林冠宏/指尖下的幽灵。转载者,请:务必标明出处。GitHub:https://github.com/af913337456/出版的书籍:《1.0-区块链DApp开发实战》《2.0-区块链DApp开发:基于公链》Ton区块链Minter与Wallet的合约部署关联细节Ton区块链的其他系列文章:Ton区块链的官方类ERC20-......
  • 中电金信:The Financial-Grade Digital Infrastructure
    01ProductIntroduction  TheFinancial-GradeDigitalInfrastructureisadigitally-enabledfoundationalframeworkdesignedforcriticalindustries,especiallythefinancialsector.Itfollowsasystematicengineeringmethodologytovalidate,customize,a......
  • Vue 打包 Error: error:0308010C:digital envelope routines::unsupported
    这个错误通常与Node.js的加密模块和OpenSSL版本有关出现这个错误是因为node.jsV17版本中最近发布的OpenSSL3.0,而OpenSSL3.0对允许算法和密钥大小增加了严格的限制,可能会对生态系统造成一些影响.js/app.8d066b51.jsfromTerserError:error:0308010C:digitalenveloperout......
  • Reflective journal about digital story
    Process:IfirstchosethestoryIpreferred,andafterfindingthestorytext,Ideliberatedrepeatedly,puttingmyselfintotheprotagonist.Imaginingwhattheprotagonistthoughtof,didandsaid,Igotthefirst-personpointofviewtext.ThenIbegan......
  • Reflective Journal on Digital Story
    Makingadigitalstoryinvolvedseveralsteps.Istartedbybrainstormingideasandthemes.Then,Icreatedastoryboard,andfindsomeaudioclips.Afterthat,Iusedvideoeditingsoftwaretopieceeverythingtogether.Finally,Ireviewedandrefinedth......
  • 2_Reflective journal about digital story
    Reflectivejournalaboutdigitalstory1) the process of making a digital story First and foremost, I decide on the story I wish to present, and afterwards, I summarize it based on its original content. Secondly, I found a few......
  • Digital SRAM-CIM for MAC
    An8TSRAMBasedDigitalCompute-In-MemoryMacroForMultiply-And-AccumulateAcceleratingintroduction相比模拟counterparts,数字CIM具有灵活的可编程性、推理精度等优势。然而,先前的工作采用复杂的SRAMbit-cells和计算部件,导致了较大的面积负担。本文提出了一种8TSRAMb......
  • index.js from Terser Error: error:0308010C:digital envelope routines::unsupporte
    Vue报错error:0308010C:digitalenveloperoutines::unsupported出现这个错误是因为node.jsV17版本中最近发布的OpenSSL3.0,而OpenSSL3.0对允许算法和密钥大小增加了严格的限制,可能会对生态系统造成一些影响.方法1.打开终端(按健win+R弹出窗口,键盘输入cmd,然后敲回车)并......