zoukankan      html  css  js  c++  java
  • 【小米oj】 国王招驸马

    基础dp

     1 #define mm(a) memset(a,0,sizeof(a));
     2 #define max(x,y) (x)>(y)?(x):(y)
     3 #define min(x,y) (x)<(y)?(x):(y)
     4 #define Fopen freopen("1.in","r",stdin); freopen("m.out","w",stdout);
     5 #define rep(i,a,b) for(int i=(a);i<=(b);i++)
     6 #define per(i,b,a) for(int i=(b);i>=(a);i--)
     7 #include<bits/stdc++.h>
     8 typedef long long ll;
     9 #define PII pair<ll,ll>
    10 using namespace std;
    11 const int INF=0x3f3f3f3f;
    12 const int MAXN=(int)2e5 + 5;
    13 const ll mod=1e9+7;
    14 
    15 
    16 string input,temp;
    17 vector<int>v;
    18 map<int,int>mp;
    19 int n,dp[MAXN],m;
    20 int main() {
    21     while(cin>>input) {
    22         istringstream iss(input);
    23         memset(dp,INF,sizeof(dp));
    24         v.clear();
    25         v.push_back(0);
    26         while (getline(iss, temp, ',')) {
    27             int x=atoi(temp.c_str());
    28             v.push_back(x);
    29         }
    30         dp[1]=0;
    31         n=v.size()-1;
    32         for(int i=1; i<=n; i++) {
    33             if(dp[i]==INF)continue;
    34             for(int j=1; j<=v[i]&&i+j<=n; j++) {
    35                 dp[i+j]=min(dp[i+j],dp[i]+1);
    36             }
    37         }
    38         if(dp[n]==INF)printf("-1
    ");
    39         else printf("%d
    ",dp[n]);
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    R中seurat等问题学习
    主成分分析PCA学习一条龙
    PAT 1116 Come on! Let's C [简单]
    PAT 1077 Kuchiguse [一般]
    R中的一些基础1106
    PAT 1036 Boys vs Girls[简单]
    稳定婚姻匹配问题模板
    University Entrace Examination zoj1023
    Stable Match
    7-1 玩转二叉树
  • 原文地址:https://www.cnblogs.com/dogenya/p/10815689.html
Copyright © 2011-2022 走看看