BestCoder Round #16 1001 Revenge of Segment Tree 1002 Revenge of LIS II
2014-11-01 22:16
316 查看
1001 | Revenge of Segment Tree |
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define ll __int64 #define MOD 1000000007 #define MAX 1000000 using namespace std; ll a[MAX]; int main(){ int T,n; scanf("%d",&T); while (T--){ scanf("%d",&n); ll sum = 0; for (int i = 0; i<n; i++) scanf("%I64d",&a[i]); for (int i = 0; i<n; i++) sum = (sum + a[i]*(i+1)%MOD*(n-i)%MOD) % MOD; printf("%I64d\n",sum); } return 0; }
1002 | Revenge of LIS II |
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define ll __int64 #define MAX 1010 using namespace std; ll dp[MAX],cnt[MAX]; int a[MAX]; int main(){ int T,n; scanf("%d",&T); while (T--){ scanf("%d",&n); for (int i = 0; i<n; i++) scanf("%d",&a[i]); for (int i = 0; i<n; i++){ dp[i] = 1; cnt[i] = 1; } for (int i = 1; i<n; i++) for (int j = i-1; j>=0; j--){ if (a[i] > a[j]){ if (dp[i] < dp[j] + 1){ cnt[i] = cnt[j]; dp[i] = dp[j] + 1; } else if (dp[i] == dp[j] + 1){ cnt[i] += cnt[j]; } } } ll ans = 0,res = 0; for (int i = 0; i<n; i++) if (ans < dp[i]){ ans = dp[i]; res = cnt[i]; } else if (ans == dp[i]){ res += cnt[i]; } if (res > 1) printf("%I64d\n",ans); else printf("%I64d\n",ans-1); } return 0; }
相关文章推荐
- Bestcoder Round #48 1001、1002
- hdu 5147 Sequence II BestCoder Round #23 1002
- BestCoder Round 69 Div 2 1001&& 1002 || HDU 5610 && 5611
- 【BestCoder】 HDOJ Revenge of LIS II
- [Bestcoder] Valentine's Day Round 1001 - Ferries Wheel | HDU 5174
- bestcoder Round-#8 1001 Summary
- hdu 4883 bestcoder round 2 1001 TIANKENG’s restaurant
- BestCoder 1st Anniversary--1001,1002解题
- BestCoder Round #32——1001——PM2.5
- BestCoder Round #70 1002 Jam's balance(DP)
- [BestCoder] Round #3 1001、1002 | HDU 4907、4908
- BestCoder Round #50 (div.2) 1001
- Bestcoder Round 15# 1001 Love
- BestCoder Round #18 1001 primes problem
- BestCoder Round #56 1002 hdu 5464 (背包问题)
- [BestCoder Round #25 1002]Harry And Magic Box 解题报告
- HDU5104 Primes Problem && BestCoder Round #18 1001
- [Bestcoder] Round #27 1001、1002 | HDU 5162、5163
- BestCoder Round #81 (div.2):1001 Machine
- 【HDU5568 BestCoder Round 63 (div1)A】【DP java高精度】sequence2 长度恰好为m的LIS数