【S - Making the Grade】

本文探讨了在数据范围过大的情况下,如何通过离散化和动态规划解决数组优化问题。介绍了从朴素DP到使用PRESUM降低时间复杂度的过程,展示了不同优化策略的效果对比。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

思路:

  • 动态规划+离散化
  • 数据范围过大,需要离散化:A【】是原数组,U【】是去重数组,dp【】是代价。
  • 心路历程:
    1. 最核心的:每改一个数必定不会改成一个在全数组中从未出现过的新数。dp 依据)
    2. dp[i][j] 代表前 i 个数符合某规则并且将最后一个元素改成数字 j 所付出的总代价,得到一个 TLE
    3. 使用滚动数组,将 dp[maxn][maxn] 改成一维,仍然 TLE
    4. 使用变量 PRESUM,降低时间复杂度。
  • 注意:
    1. 两种规则(不升\不降)只需要一次 reverse
    2. 用到的STL:unique、reserve、min_element 。

代码:

  • 朴素dp:TLE
//TLE


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> 
#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 2005;

int N;
int M;
int ans;
int A[maxn];
int U[maxn];
int dp[maxn][maxn]; 

int SOLVE(){
	for(int i=0;i<M;i++)
		dp[0][i] = abs(A[0] - U[i]);
	for(int i=1;i<N;i++){
		for(int j=0;j<M;j++){
			int MIN = INF;
			for(int k=0;k<=j;k++)//前面的(i-1)个数优化到全部(x)于U[j]的非(x)序列 的代价 
				MIN = min(MIN , dp[i-1][k]);
			dp[i][j] = MIN + abs(A[i] - U[j]);
		}
	}
	return *min_element(dp[N-1] , dp[N-1] + M);
}

int main(){
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>A[i] , U[i] = A[i];
	sort(U , U + N);
	M = unique(U , U + N) - U;
	ans = INF;
	ans = min(ans , SOLVE());
	reverse(U , U + N);
	ans = min(ans , SOLVE());
	cout<<ans<<endl;
	return 0;
}
  • 滚动数组:TLE
//TLE


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> 
#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 2005;

int N;
int M;
int ans;
int A[maxn];
int U[maxn];
int dp[maxn]; 

int SOLVE(){
	memset(dp , 0 , sizeof(dp));
	for(int i=0;i<N;i++){
		for(int j=M-1;j>=0;j--){
			//注意需要改成倒序
			int MIN = INF;
			for(int k=0;k<=j;k++)//前面的(i-1)个数优化到全部(x)于U[j]的非(x)序列 的代价
				MIN = min(MIN , dp[k]);
			dp[j] = MIN + abs(A[i] - U[j]);
		}
	}
	return *min_element(dp , dp + M);
}

int main(){
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>A[i] , U[i] = A[i];
	sort(U , U + N);
	M = unique(U , U + N) - U;
	ans = INF;
	ans = min(ans , SOLVE());
	reverse(U , U + N);
	ans = min(ans , SOLVE());
	cout<<ans<<endl;
	return 0;
}
  • PRESUM:79ms 748kB
//79ms		748kB


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> 
#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 2005;

int N;
int M;
int ans;
int A[maxn];
int U[maxn];
int dp[maxn]; 

int SOLVE(){
	memset(dp , 0 , sizeof(dp));
	for(int i=0;i<N;i++){
		int PRESUM = INF;
		for(int j=0;j<M;j++){
			PRESUM = min(PRESUM , dp[j]);
			dp[j] = PRESUM + abs(A[i] - U[j]);
		}
	}
	return *min_element(dp , dp + M);
}

int main(){
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>A[i] , U[i] = A[i];
	sort(U , U + N);
	M = unique(U , U + N) - U;
	ans = INF;
	ans = min(ans , SOLVE());
	reverse(U , U + N);
	ans = min(ans , SOLVE());
	cout<<ans<<endl;
	return 0;
}
### 100 Gb/s Polarization Division Multiplexing Quadrature Phase Shift Keying Technology #### Overview of PDM-QPSK Polarization division multiplexing combined with quadrature phase shift keying (PDM-QPSK) is a modulation technique that significantly increases the transmission capacity over single-wavelength channels by utilizing both polarizations of light and advanced signal processing techniques. This method has become an industry standard due to its efficient bandwidth utilization and excellent interference resistance properties[^2]. The core principle behind QPSK involves dividing binary sequences into groups of two bits each, resulting in four distinct states represented by different phases of the carrier wave separated by π/2 radians. Each pair corresponds uniquely to one out of four possible initial phases on the carrier waveform, effectively converting the baseband information from binary form into quaternary format[^3]. When this scheme is further enhanced through polarization multiplexing, it allows simultaneous transmission along orthogonal axes within the same optical channel. #### System Architecture for Coherent Optical Communication at 100 Gb/s Using Optisystem Software To implement such high-speed communications systems operating at rates up to 100 gigabits per second using PDM-QPSK signaling requires sophisticated design considerations across multiple domains including optics, electronics, as well as digital signal processing algorithms implemented via software tools like MATLAB or specialized platforms designed specifically around photonic simulation environments such as OptiSystem: - **Transmitter Module**: Generates modulated signals based upon input data streams which are then split between X & Y axis before being encoded onto respective carriers. - **Transmission Medium**: Utilizes fiber optic cables optimized for minimal loss characteristics while supporting higher bitrates without significant degradation issues even over long distances exceeding thousands kilometers when paired appropriately alongside dispersion compensation methods where necessary. - **Receiver Unit**: Employs coherent detection schemes capable of demodulating complex multi-level formats efficiently; post-processing steps involve equalization followed by symbol decision making processes ultimately recovering original transmitted payload accurately despite potential impairments encountered during transit. ```matlab % Example Code Snippet Demonstrating Basic DSP Algorithm Implementation For Decoding Received Signal In Matlab Environment function decoded_bits = decode_pdm_qpsk(received_signal) % Perform synchronization and timing recovery here... % Equalize received symbols eq_symbols = equalizer_function(received_signal); % Demap constellation points back to bits decoded_bits = []; for k=1:length(eq_symbols)/2 idx_x = 2*k-1; idx_y = 2*k; point = [real(eq_symbols(idx_x)), imag(eq_symbols(idx_y))]; [~, nearest_idx] = min(sum((point - qpsk_constellation).^2)); decoded_bit_pair = degray_code(nearest_idx); %#ok<DEMG> decoded_bits = [decoded_bits ; num2str(decoded_bit_pair)-'0']; end end ``` #### Applications Within Information Technology Field In today's rapidly evolving technological landscape characterized by increasing demands placed upon network infrastructures supporting diverse applications ranging from cloud computing services down to consumer-grade entertainment offerings requiring ultra-low latency connections coupled together seamlessly – all these factors contribute towards driving forward advancements seen recently regarding deployment strategies surrounding next-generation passive optical networks (NG-PON). Specifically targeting residential broadband access solutions aiming beyond current standards set forth previously established under GPON specifications toward newer paradigms embodied now within proposals concerning 25G PON and eventually progressing onward reaching speeds potentially surpassing those offered currently available commercially viable options existing presently day-to-day operations conducted online daily basis worldwide scale[^4].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值