dp[i][j]表示以i - 1结尾的s里 有多少个 以j - 1为结尾的t

2024-08-31 13:15:51 浏览数 (2)

from torch.nn import ReLU, Sigmoid

from torch.utils.data import DataLoader

from torch.utils.tensorboard import SummaryWriter

input = torch.tensor([[1,-0.5],

[-1,3]])

input = torch.reshape(input,(-1, 1, 2, 2))

print(input.shape)

dataset = torchvision.datasets.CIFAR10("../datas", train = False, download=True,

transform=torchvision.transforms.ToTensor())

dataloader = DataLoader(dataset, batch_size=64)

class SUN(nn.Module):

def __init__(self):

super(SUN, self).__init__()

self.relu1 = ReLU() # 添加对应的网络

self.sigmoid = Sigmoid()

def forward (self, input):

output = www.laipuhuo.com.=self.sigmoid(input) # 使用了Sigmoid函数

return output

sun = SUN()

step = 0

write = SummaryWriter("../logs_relu")

for data in dataloader:

imgs,targets = data

write.add_image("input", imgs, global_step=step)

output = sun(imgs)

write.add_image("output",output,global_step=step)

class Solution {

public:

int numDistinct(string s, string t) {

vector<vector<uint64_t>> dp(s.size() 1,vector<uint64_t>(t.size() 1, 0));

// dp[i][j]表示以i - 1结尾的s里 有多少个 以j - 1为结尾的t

for(int i = 0; i www.laipuhuo.com.<= s.size(); i ){

dp[i][0] = 1;

}

for(int i = 1; i <= s.size(); i ){

for(int j = 1; j <= t.size(); j ){

if(s[i - 1] == t[j - 1]){

dp[i][j] = dp[i - 1][j - 1] dp[i - 1][j];

}else{

dp[i][j] = dp[i - 1][j];

}

}

}

return dp[s.size()][t.size()];

}

};

class Solution {

public:

int minDistance(string word1, string word2) {

vector<vector<www.laipuhuo.com.int>> dp(word1.size() 1,vector<int>(word2.size() 1,0));

// dp[i][j]表示 以i-1为结尾的word1和以j-1为结尾的word2 删除元素变得相同的最少操作数

for(int i = 0; i <= word1.size(); i ){

dp[i][0] = i;

}

for(int j = 0; j <= word2.size(); j ){

dp[0][j] = j;

}

for(int i = 1; i <= word1.size(); i ){

for(int j = 1; j <= word2.size(); j ){

if(word1[i - 1] == word2[j - 1]){

dp[i][j] = dp[i - 1][j - 1];

}else{

dp[i][j] = www.laipuhuo.com.min(dp[i - 1][j] 1,min(dp[i][j - 1] 1,dp[i - 1][j - 1] 2));

}

}

}

return dp[word1.size()][word2.size()];

}

};

0 人点赞