Atcoder
DP
有 N 個石頭,給個石頭有不同高度,一隻青蛙從第一顆石頭開始,每次可以選擇跳一格或兩格而每從第 i 個跳到第 j 個的花費為兩石頭高度相減的絕對值,最後回傳總花費最小值為何。
先輸入總共有 N 個石頭,再依序輸入第 i 個石頭的高度
到達地 N 個石頭前最小的花費
每到一塊石頭,就去比較前兩塊跳過來的花費,並選擇最小值加總。
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
int dp[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
dp[0]=0;
dp[1]=abs(a[1]-a[0]);
for(int i=2;i<n;i++){
dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
}
cout<<dp[n-1]<<endl;
return 0;
}
PeterWang
Sun, Jun 13, 2021 10:00 AM
Request for GPU
Mar 14, 2025Introduction This article delves into the architecture and mechanics of decoder-only transformers, which are a crucial component of many large language models (LLMs). It highlights the structure, attention mechanisms, and embedding techniques that make these models effective for various natural language processing (NLP) tasks. Decoder-Only Transformer Architecture Overview Decoder-only transformers, unlike the traditional encoder-decoder structure, use only the decoder component to process and generate text. This architecture is particularly suited for tasks that involve sequential generation, such as text completion and language modeling. Structure The decoder-only transformer consists of multiple layers, each containing self-attention mechanisms and feed-forward neural networks.
Jun 26, 2024Introduction This article provides a visual and intuitive explanation of the transformer architecture, which has revolutionized natural language processing (NLP) by enabling efficient handling of sequential data through self-attention mechanisms. It covers the structure, mechanics, and key components such as the encoder, decoder, attention mechanisms, and embeddings. Transformer Architecture Overview The transformer architecture, introduced by Vaswani et al. in 2017, eliminates the need for recurrent layers by using self-attention mechanisms, allowing for parallel processing and better handling of long-range dependencies. Encoder-Decoder Structure The transformer model consists of an encoder-decoder architecture, each composed of multiple layers.
Jun 26, 2024This article offers a detailed explanation of transformers, a revolutionary architecture in natural language processing (NLP) that has significantly advanced the capabilities of large language models (LLMs). It covers the structure, mechanics, and key components of transformers, including the encoder, decoder, attention mechanisms, and embeddings.
Jun 26, 2024or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up