zoukankan      html  css  js  c++  java
  • Leetcode-403 Frog Jump(青蛙过河)

     1 #define pb push_back
     2 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
     3 class Solution
     4 {
     5     public:
     6         bool canCross(vector<int>& stones)
     7         {
     8             int sz = stones.size();
     9             if(sz==2&&stones[1]==1) return true;
    10 
    11             vector<set<int>> dp(sz);
    12             dp[0].insert(0);
    13             for(int i = 1; i < sz; i ++)
    14             {
    15                 int szz = dp[i-1].size();
    16                 cout << szz << endl;
    17                 for(auto j = dp[i-1].begin(); j != dp[i-1].end(); j ++)
    18                 {
    19                     if(binary_search(stones.begin(),stones.end(),stones[i-1]+*j))
    20                         dp[lower_bound(stones.begin(),stones.end(),stones[i-1]+*j)-stones.begin()].insert(*j);
    21                     if(binary_search(stones.begin(),stones.end(),stones[i-1]+*j+1))
    22                         dp[lower_bound(stones.begin(),stones.end(),stones[i-1]+*j+1)-stones.begin()].insert(*j+1);
    23                     if(*j!=1&&binary_search(stones.begin(),stones.end(),stones[i-1]+*j-1))
    24                         dp[lower_bound(stones.begin(),stones.end(),stones[i-1]+*j-1)-stones.begin()].insert(*j-1);
    25                 }
    26             }
    27             if(dp[sz-1].empty())
    28                 return false;
    29             return true;
    30         }
    31 };
  • 相关阅读:
    mysql 函数
    flanneld和calico
    k8s1.20.5
    pre
    docker与K8S源远
    Form Trigger Sequence Demo Form
    消息中间件RabbitMQ
    asp.net mvc4压缩混淆JavaScript
    C# 基础语法
    APP测试 理论总结
  • 原文地址:https://www.cnblogs.com/Asurudo/p/10350968.html
Copyright © 2011-2022 走看看