• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Sephiroth's boring days!!!

            Love just for you.

            CTSC98-選課

            有依賴的背包,正好剛剛學(xué)到。

              1: #include <stdio.h>
            
              2: #include <stdlib.h>
            
              3: #define maxn 400
            
              4: 
            
              5: int f[maxn][maxn];
            
              6: int t[maxn];
            
              7: struct ss
            
              8: {
            
              9:     int root,num;
            
             10: } a[maxn];
            
             11: int n,m;
            
             12: int w[maxn];
            
             13: 
            
             14: int cmp(const void*a,const void*b)
            
             15: {
            
             16:     ss c=*(ss*)a,d=*(ss*)b;
            
             17:     if (c.root<d.root) return -1;
            
             18:     if (c.root>d.root) return 1;
            
             19:     return 0;
            
             20: }
            
             21: 
            
             22: void dp(int x)
            
             23: {
            
             24:     for (int i=t[x];i<t[x+1];++i)
            
             25:     {
            
             26:         int k=a[i].num;
            
             27:         for (int j=0;j<=m;++j) f[k][j]=f[x][j]+w[k];
            
             28:         dp(k);
            
             29:         for (int j=1;j<=m;++j)
            
             30:             if (f[k][j-1]>f[x][j])
            
             31:                 f[x][j]=f[k][j-1];
            
             32:     }
            
             33: }
            
             34: 
            
             35: int main()
            
             36: {
            
             37:     scanf("%d%d",&n,&m);
            
             38:     for (int i=1;i<=n;++i)
            
             39:     {
            
             40:         scanf("%d%d",&a[i].root,&w[i]);
            
             41:         a[i].num=i;
            
             42:     }
            
             43:     a[0].root=-1;
            
             44:     qsort(a,n+1,sizeof(ss),cmp);
            
             45:     for (int i=1;i<=n;++i)
            
             46:         if (!t[a[i].root])
            
             47:             t[a[i].root]=i;
            
             48:     t[n+1]=n+1;
            
             49:     for (int i=n;i>=0;--i)
            
             50:         if (!t[i])
            
             51:             t[i]=t[i+1];
            
             52:     dp(0);
            
             53:     printf("%d\n",f[0][m]);
            
             54:     return 0;
            
             55: }
            
             56: 

            posted on 2010-08-27 18:05 Sephiroth Lee 閱讀(451) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 信息奧賽

            free counters
            亚洲午夜久久久精品影院| 日韩AV无码久久一区二区 | 亚洲午夜精品久久久久久浪潮 | 蜜臀av性久久久久蜜臀aⅴ | 久久精品三级视频| 亚洲色欲久久久综合网| 99久久久精品| 久久亚洲精品国产精品婷婷| 国产精品九九九久久九九| 欧美日韩中文字幕久久久不卡| 久久99国产综合精品女同| 久久最新免费视频| 国产精品久久久久AV福利动漫| 香港aa三级久久三级老师2021国产三级精品三级在 | 爱做久久久久久| 影音先锋女人AV鲁色资源网久久 | 久久久久久久97| 久久久久国色AV免费观看| 久久99精品国产麻豆| 99久久夜色精品国产网站| 久久亚洲欧洲国产综合| 91精品国产91久久| 久久久久夜夜夜精品国产| 久久综合给合久久国产免费| 日本国产精品久久| 久久伊人中文无码| 精品久久久无码中文字幕天天| 久久国产一区二区| 亚洲国产成人久久综合一| 欧美亚洲另类久久综合| 久久99精品国产| 久久青青草原国产精品免费| 久久精品国产半推半就| 99麻豆久久久国产精品免费| AV狠狠色丁香婷婷综合久久 | 久久国产免费| 亚洲午夜久久久| 久久午夜免费视频| 午夜天堂av天堂久久久| 久久久久亚洲AV无码永不| 国产精品久久波多野结衣|