cf C. Fox and Box Accumulation

來源:互聯網
上載者:User

標籤:

題意:輸入一個n,然後輸入n個數,問你可以劃分多少個序列,序列為:其中一個數為c,在它的前面最多可以有c個數。

思路:先排序,然後對於每一個數逐步的找沒有被用過的數,且這個數可以符合條件,然後如果沒有找到,結果加1;最後就是答案。

 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5  6 int n; 7 int x[200]; 8 int num[200]; 9 int dp[200][200];10 bool vis[200];11 12 int main()13 {14     while(scanf("%d",&n)!=EOF)15     {16         for(int i=0; i<n; i++)17         {18             scanf("%d",&x[i]);19         }20         memset(vis,false,sizeof(vis));21         sort(x,x+n);22         int ans=0;23         for(int i=0; i<n; i++)24         {25             num[i]=1;26         }27         for(int i=0; i<n; i++)28         {29             int m=num[i];30             bool flag=false;31             for(int j=i; j<n; j++)32             {33                 if(x[j]>=m&&num[j]==1&&j!=i)34                 {35                    flag=true;36                    num[j]+=m;37                    break;38                 }39             }40             if(!flag) ans++;41         }42         printf("%d\n",ans);43     }44     return 0;45 }
View Code

 

cf C. Fox and Box Accumulation

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.