This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn.functional as F | |
from tqdm import tqdm | |
class Gaussian(object): | |
def __init__(self, mu, rho): | |
super().__init__() | |
self.mu = mu | |
self.rho = rho |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name leetcode题解助手 | |
// @namespace leetcode_helper | |
// @version 1.2.0 | |
// @description 查找leetcode题解(九章算法的题解搜索,C++答案搜索, 提供Github上开源的python题解的一键查询按钮,可以直接在谷歌搜索题目名称,还能切换语言) | |
// @author sherpahu & zjplab | |
// @icon https://assets.leetcode.com/static_assets/public/webpack_bundles/images/logo-dark.e99485d9b.svg | |
// @include *://leetcode-cn.com/problems/* | |
// @include *://leetcode.com/problems/* | |
/************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python program to demonstrate delete operation | |
# in binary search tree | |
# A Binary Tree Node | |
class Node: | |
# Constructor to create a new node | |
def __init__(self, key): | |
self.key = key | |
self.left = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python program to print all permutations with | |
# duplicates allowed | |
def toString(List): | |
return ''.join(List) | |
# Function to print permutations of string | |
# This function takes three parameters: | |
# 1. String | |
# 2. Starting index of the string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A complete working C program to demonstrate deletion in singly | |
// linked list | |
#include <stdio.h> | |
#include <stdlib.h> | |
// A linked list node | |
struct node | |
{ | |
int data; | |
struct node *next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// A utility function that returns maximum of two integers | |
int max(int a, int b) { return (a > b)? a : b; } | |
// Returns the maximum value that can be put in a knapsack of capacity W | |
int knapsack(int val[], int weight[],int w,int n) | |
{ | |
if(n==0 || w==0 ) return 0; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int LIS(int arr[],int n){ | |
//base case | |
if(n==1) return 1; | |
//otherwise | |
int curr_max=1; | |
for(int i=0;i<n-1;++i){ // i< n-1 because n>=2 | |
while(arr[i]<arr[n-1] ){ | |
int subproblem=LIS(arr,i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Consider finding a shortest path for travelling between two cities by car, as illustrated in Figure 1. Such an example is likely to exhibit optimal substructure. That is, if the shortest route from Seattle to Los Angeles passes through Portland and then Sacramento, then the shortest route from Portland to Los Angeles must pass through Sacramento too. That is, the problem of how to get from Portland to Los Angeles is nested inside the problem of how to get from Seattle to Los Angeles. (The wavy lines in the graph represent solutions to the subproblems.) | |
As an example of a problem that is unlikely to exhibit optimal substructure, consider the problem of finding the cheapest airline ticket from Buenos Aires to Kyiv. Even if that ticket involves stops in Miami and then London, we can't conclude that the cheapest ticket from Miami to Kyiv stops in London, because the price at which an airline sells a multi-flight trip is usually not the sum of the prices at which it would sell the individual flights in the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kadane’s Algorithm: | |
Initialize: | |
max_so_far = 0 | |
max_ending_here = 0 | |
Loop for each element of the array | |
(a) max_ending_here = max_ending_here + a[i] | |
(b) if(max_ending_here < 0) | |
max_ending_here = 0 |
NewerOlder