标签:记录 ems 序列 循环 div ns2 eof scanf can
51nod 1134 最长递增子序列
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define rep(i,l,r) for (int i=l; i<=r; i++) typedef long long ll; using namespace std; const int N = 5e4+10; int n, s[N]; int dp[N]; int main(){ freopen("in.txt","r",stdin); //freopen("a.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d", &s[i]); memset(dp,0x3f,sizeof(dp)); for(int i=1;i<=n;i++) { int l = lower_bound(dp+1,dp+1+N,s[i])-(dp); dp[l] = s[i]; } int ans = lower_bound(dp+1,dp+1+N,0x3f3f3f3f)-dp -1; cout << ans<<endl; return 0; }
51nod 1050 循环数组最大子段和
考虑 成环的一个最大字段和 要么是正常的字段和 要么是整个环的总和 - (负的最大的 最小子段和)
#include<bits/stdc++.h> using namespace std; const int maxn = 5e4+10; int a[maxn],b[maxn],n; typedef long long ll; ll solve (int *s) { ll ans =0,res =0; for(int i=0;i<n;i++) { ans+=s[i]; res = max(res,ans); if(ans < 0) ans =0; } return res; } int main () { scanf("%d",&n); ll res=0; for(int i=0;i<n;i++) { scanf("%d",&a[i]); b[i] = -a[i]; res += a[i]; } ll ans1= solve(a),ans2=solve(b); res= max(ans1,res+ans2); printf("%lld\n",res); return 0; }
标签:记录 ems 序列 循环 div ns2 eof scanf can
原文地址:https://www.cnblogs.com/Draymonder/p/9533218.html