codeforce#933 题解

马肤
这是懒羊羊

E. Rudolf and k Bridges

题意不讲了,不如去题干看图。

传统dp,每个点有两个选择,那么建桥要么不建。需要注意的是在状态转移的时候,桥是有长度的,如果不建需要前d格中建桥花费最少的位置作为状态转移的初态。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
#define IOS     ios::sync_with_stdio(0);cin.tie(0);
#define mem(A,B) memset(A,B,sizeof(A));
#define rep(index,start,end) for(int index = start;index = end; index --)
 
using namespace std;
 
typedef long long ll;
const int maxn = 2e5+5;
struct contianer {
    private:
        int step;
        int pos = 0;
        ll loop[maxn];
        multiset store;
    public:
        contianer(int step):step(step) {}
        
        void add(ll x) {
            int now = pos % step;
            // need to remove
            if (pos >= step) {
                store.erase(store.find(loop[now]));
            }
            
            loop[now] = x;
            store.insert(x);
            pos ++;
        }
        
        /**
          * get min number
         */
        ll get() {
            return *store.begin();
        }
        
        void setStep(int s);
        
        void clear();
};
void contianer::setStep(int s) {
    step = s;
}
void contianer::clear() {
    store.clear();
    pos = 0;
}
ll sum[128];
int store[maxn];
ll dp[maxn][2];
int main() {
    IOS
    
    int t;
    cin>>t;
    while(t--) {
        int n,m,k,d;
        cin>>n>>m>>k>>d;
        contianer heap(d);
        
        sum[0] = 0LL;
        // input and dp
        rep(_,0,n) {
            // input
            rep(i,0,m) cin>>store[i];
            // init
            heap.clear();
            heap.add(store[0] + 1);
            dp[0][0] = dp[0][1] = store[0] + 1;
            // dp
            rep(i,1,m-1) {
                ll min_cost = heap.get();
                dp[i][0] = min_cost;
                dp[i][1] = min(dp[i-1][0], min_cost) + store[i] + 1;
//                cout
            ans = min(ans, sum[i] - sum[i-k]);
        }
        // cout
        cout
    int val;
    int ind;
};
int store[maxn/2];
record dif[maxn/2];
int d[maxn], f[maxn];
bool cmp(const record& a, const record& b) {
    return a.val 

文章版权声明:除非注明,否则均为VPS857原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复:表情:
评论列表 (暂无评论,0人围观)

还没有评论,来说两句吧...

目录[+]

取消
微信二维码
微信二维码
支付宝二维码