日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Luogu2439 [SDOI2005]阶梯教室设备利用 (动态规划)

發布時間:2023/12/10 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Luogu2439 [SDOI2005]阶梯教室设备利用 (动态规划) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

同上一題,區間改左閉右開就雙倍經驗了。貌似可以跑最長路。

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define R(a,b,c) for(register int a = (b); a <= (c); ++ a) #define nR(a,b,c) for(register int a = (b); a >= (c); -- a) #define Max(a,b) ((a) > (b) ? (a) : (b)) #define Min(a,b) ((a) < (b) ? (a) : (b)) #define Fill(a,b) memset(a, b, sizeof(a)) #define Abs(a) ((a) < 0 ? -(a) : (a)) #define Swap(a,b) a^=b^=a^=b #define ll long long#define ON_DEBUG#ifdef ON_DEBUG#define D_e_Line printf("\n\n----------\n\n") #define D_e(x) cout << #x << " = " << x << endl #define Pause() system("pause") #define FileOpen() freopen("in.txt","r",stdin);#else#define D_e_Line ; #define D_e(x) ; #define Pause() ; #define FileOpen() ;#endifstruct ios{template<typename ATP>ios& operator >> (ATP &x){x = 0; int f = 1; char c;for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();x*= f;return *this;} }io; using namespace std;const int N = 10007;struct Field{int l, r, w;bool operator < (const Field &com) const{if(r != com.r) return r < com.r;return l < com.l;} }a[N];int f[N];inline int Find(int x){int l = 1, r = x;int ans = -1;while(l <= r){int mid = (l + r) >> 1;if(a[mid].r < a[x].l){l = mid + 1;ans = mid;}else{r = mid - 1;}}return ans; } int main(){//FileOpen();int n;io >> n;R(i,1,n){io >> a[i].l >> a[i].r;--a[i].r;a[i].w = a[i].r - a[i].l + 1;}sort(a + 1, a + n + 1);f[1] = a[1].w;R(i,2,n){int j = Find(i);if(j != -1)f[i] = Max(f[i - 1], f[j] + a[i].w);elsef[i] = Max(f[i - 1], a[i].w);}printf("%d\n",f[n]);return 0; }

轉載于:https://www.cnblogs.com/bingoyes/p/11221389.html

總結

以上是生活随笔為你收集整理的Luogu2439 [SDOI2005]阶梯教室设备利用 (动态规划)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。