查看: 1906|回復: 0
打印 上一主題 下一主題

[HOJ] 303 - 買醬油IV 之 商店問題

[複製鏈接]

該用戶從未簽到

10

主題

32

帖子

163

積分

高一新生

Rank: 2

積分
163

台南一中資訊社新手達陣

跳轉到指定樓層
樓主
發表於 2014-4-21 13:08:34 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式

趕快加入我們來參與討論吧!

您需要 登錄 才可以下載或查看,沒有帳號?加入我們

x
本帖最後由 ForTest 於 2014-4-23 07:44 編輯

題目:http://hoj.twbbs.org/judge/problem/view/303
AC code:http://ideone.com/uZEIoK
找出字典序最小的LIS
也就是從後面開始做LDS
詳細證明見演算法筆記
http://www.csie.ntnu.edu.tw/~u91 ... gSubsequence.html#3

Submission id:19877 Status:AC
http://hoj.twbbs.org/judge/judge/submission/19877
#include <iostream>
  • #include <cstdio>
  • #include <cstring>
  • #include <vector>
  • #include <algorithm>
  • #include <map>
  • #include <queue>
  • #include <sstream>

  • using namespace std;

  • #define F(a,b) for(int a=0;a<b;++a)
  • typedef long long LL;

  • const int Max = 1e5 + 10;

  • LL n,ans,p[Max],s[Max];
  • vector<LL> lis;

  • bool cmp(LL a,LL b){ return a > b; }
  • void Lis(){
  •     int pos = 0;
  •     for(int i=n-1;i>=0;--i)
  •         if((i == n-1) || (s[i] < lis.back())){
  •             lis.push_back(s[i]);
  •             p[i] = (++pos);
  •         }
  •         else{
  •             vector<LL>::iterator l = lower_bound(lis.begin(),lis.end(),s[i],cmp);
  •             *l = s[i];
  •             p[i] = l - lis.begin() + 1;
  •         }
  •     F(i,n) if(p[i] == pos){
  •         ans += i+1;
  •         pos --;
  •     }
  • }

  • int main(){
  •     scanf("%lld",&n);
  •     F(i,n) scanf("%lld",&s[i]);
  •     Lis();
  •     printf("%lld\n",ans);
  • }




  • 評分

    參與人數 1金幣 +3 收起 理由
    Sylveon + 3

    查看全部評分

    回復

    使用道具 檢舉

    您需要登錄後才可以回帖 登入 | 加入我們

    本版積分規則

    快速回覆 返回頂部 返回列表