P1233-木棍加工
Posted asurudo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了P1233-木棍加工相关的知识,希望对你有一定的参考价值。
1 #pragma GCC optimize("Ofast") 2 #include <bits/stdc++.h> 3 #define maxn 13003 4 #define _for(i,a,b) for(int i = (a);i < b;i ++) 5 typedef long long ll; 6 using namespace std; 7 8 inline ll read() 9 10 ll ans = 0; 11 char ch = getchar(), last = ‘ ‘; 12 while(!isdigit(ch)) last = ch, ch = getchar(); 13 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - ‘0‘, ch = getchar(); 14 if(last == ‘-‘) ans = -ans; 15 return ans; 16 17 inline void write(ll x) 18 19 if(x < 0) x = -x, putchar(‘-‘); 20 if(x >= 10) write(x / 10); 21 putchar(x % 10 + ‘0‘); 22 23 struct wood 24 25 int W; 26 int L; 27 ; 28 int n; 29 wood in[5003]; 30 int dp[5003]; 31 int dpend = 1; 32 bool cmp(wood a,wood b) 33 34 if(a.L == b.L) 35 return a.W > b.W; 36 return a.L > b.L; 37 38 39 int main() 40 41 n = read(); 42 _for(i,1,n+1) 43 44 in[i].L = read(); 45 in[i].W = read(); 46 47 sort(in+1,in+n+1,cmp); 48 49 dp[dpend] = in[1].W; 50 _for(i,2,n+1) 51 52 if(in[i].W > dp[dpend]) 53 dp[++dpend] = in[i].W; 54 else 55 56 int t = lower_bound(dp+1,dp+dpend+1,in[i].W)-dp; 57 dp[t] = in[i].W; 58 59 60 write(dpend); 61 return 0; 62
以上是关于P1233-木棍加工的主要内容,如果未能解决你的问题,请参考以下文章