Deleon 2024-02-18 64 0 0 0 0
视频AI,Sora,马斯克,马斯克评OpenAISora昨天,OpenAI发布了首个视频生成模型Sora。一位X(前推特)用户分享了Sora官网所展示的生成视频:一名女子在东京街头漫步。帖子底下另一位X网友评论称:ggPixa…

马斯克评 OpenAI Sora

昨天,OpenAI 发布了首个视频生成模型 Sora。

一位 X(前推特)用户分享了 Sora 官网所展示的生成视频:一名女子在东京街头漫步。

Image
,时长00:59

该用户评论称:"OpenAI 今天宣布了 Sora,它使用transformer模型架构生成长达 1 分钟的视频,他们似乎又领先了其他所有人1-2年"。

马斯克评 OpenAI 视频模型

帖子底下另一位 X 网友评论称:"gg Pixar"。

这里说的 Pixar 是指皮克斯动画工作室(Pixar Animation Studio),全球领先的专门制作电脑动画的公司。

而 gg 是网络游戏用语 "good games" 的缩写,主要用于游戏结束后,多由失败方发出,表示认赌服输、心服口服的意思。

世界首富兼人类网红天花板的马斯克则直接回应称:"gg humans"。

确实,Sora 只是 OpenAI 在视频领域的前期首个模型,就已经给世界亿点点震撼了,往后真的不可想象。

...

回归主线。

随着复工日期越来越近,主线任务也逐步恢复到正常难度水平。

来一道「华为」专业评级考试原题醒醒脑。

...

题目描述

平台:LeetCode

题号:2698

给你一个正整数 n,请你返回 n 的惩罚数。

 n的惩罚数定义为所有满足以下条件  的数的平方和:

1<=i<=n

ixi 的十进制表示的字符串可以分割成若干连续子字符串,且这些子字符串对应的整数值之和等于 

示例 1:

输入:n = 10

输出:182

解释:总共有 3 个整数 i 满足要求:
- 1 ,因为 1 * 1 = 1
- 9 ,因为 9 * 9 = 81 ,且 81 可以分割成 8 + 1 。
- 10 ,因为 10 * 10 = 100 ,且 100 可以分割成 10 + 0 。
因此,10 的惩罚数为 1 + 81 + 100 = 182

示例 2:

输入:n = 37

输出:1478

解释:总共有 4 个整数 i 满足要求:
- 1 ,因为 1 * 1 = 1
- 9 ,因为 9 * 9 = 81 ,且 81 可以分割成 8 + 1 。
- 10 ,因为 10 * 10 = 100 ,且 100 可以分割成 10 + 0 。
- 36 ,因为 36 * 36 = 1296 ,且 1296 可以分割成 1 + 29 + 6 。
因此,37 的惩罚数为 1 + 81 + 100 + 1296 = 1478

提示:

1<=n<=1000

...

递归

一个朴素的做法是遍历[1,i] ,若当前数值i 满足要求,则将ixi累加到答案中。

问题关键转为:如何判定ixi  是否能够分割成多个整数,使其累加值为 i。

简单做法是通过递归来做:每次从当前值的低位开始截取,通过「取余」和「地板除」操作,得到截取部分和剩余部分,再继续递归处理。

Java 代码:

class Solution {
    public int punishmentNumber(int n) {
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (check(i * i, i)) ans += i * i;
        }
        return ans;
    }
    boolean check(int t, int x) {
        if (t == x) return true;
        int d = 10;
        while (t >= d && t % d <= x) {
            if (check(t / d, x - (t % d))) return true;
            d *= 10;
        }
        return false;
    }
}

Python 代码:

class Solution:
    def punishmentNumber(self, n: int) -> int:
        def check(t, x):
            if t == x:
                return True
            d = 10
            while t >= d and t % d <= x:
                if check(t // d, x - (t % d)):
                    return True
                d *= 10
            return False
        return sum([i * i if check(i * i, i) else 0 for i in range(1, n + 1)])

C++ 代码:

class Solution {
public:
    bool check(int t, int x) {
        if (t == x) return true;
        int d = 10;
        while (t >= d && t % d <= x) {
            if (check(t / d, x - (t % d))) return true;
            d *= 10;
        }
        return false;
    }
    int punishmentNumber(int n) {
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (check(i * i, i)) ans += i * i;
        }
        return ans;
    }
};

TypeScript 代码:

function punishmentNumber(n: number): number {
    function check(t: number, x: number): boolean {
        if (t === x) return true;
        let d = 10;
        while (t >= d && t % d <= x) {
            if (check(Math.floor(t / d), x - (t % d))) return true;
            d *= 10;
        }
        return false;
    }
    let ans = 0;
    for (let i = 1; i <= n; i++) {
        if (check(i * i, i)) ans += i * i;
    }
    return ans;
};
  • 时间复杂度:O(n log n的平方)
  • 空间复杂度:O(log n的平方)

...

打表

更进一步,对于[1,x] 范围内的惩罚数必然包含了 [1,y](其中y

即多个样例之间必然存在重复计算,我们可通过「打表」进行预处理:定义f{i}  为n=i  时的答案(惩罚数),对于f{i}  而言,起始为 f{i-1},若数值 i 本身满足要求,则将 ixi  累加到  f{i} 当中。

Java 代码:

class Solution {
    static int[] f = new int[1010];
    static {
        for (int i = 1; i <= 1000; i++) {
            f[i] = f[i - 1];
            if (check(i * i, i)) f[i] += i * i;
        }
    }
    static boolean check(int t, int x) {
        if (t == x) return true;
        int d = 10;
        while (t >= d && t % d <= x) {
            if (check(t / d, x - (t % d))) return true;
            d *= 10;
        }
        return false;
    }
    public int punishmentNumber(int n) {
        return f[n];
    }
}

Python 代码:

def check(t, x):
    if t == x:
        return True
    d = 10
    while t >= d and t % d <= x:
        if check(t // d, x - (t % d)):
            return True
        d *= 10
    return False
f = [0] * 1010
for i in range(1, 1010):
    f[i] = f[i - 1] + (i * i if check(i * i, i) else 0)
class Solution:
    def punishmentNumber(self, n: int) -> int:
        return f[n]

C++ 代码:

inline bool check(int t, int x) {
    if (t == x) return true;
    int d = 10;
    while (t >= d && t % d <= x) {
        if (check(t / d, x - (t % d))) return true;
        d *= 10;
    }
    return false;
}
int f[1010];
int _ = []() {
    for (int i = 1; i < 1010; i++) {
        f[i] = f[i - 1];
        if (check(i * i, i)) f[i] += i * i;
    }
    return 0;
}();
class Solution {
public:
    int punishmentNumber(int n) {
        return f[n];
    }
};

TypeScript 代码:

function check(t: number, x: number): boolean {
    if (t === x) return true;
    let d = 10;
    while (t >= d && t % d <= x) {
        if (check(Math.floor(t / d), x - (t % d))) return true;
        d *= 10;
    }
    return false;
}
const f = new Array(1010).fill(0);
for (let i = 1; i < 1010; i++) {
    f[i] = f[i - 1];
    if (check(i * i, i)) f[i] += i * i;
}
function punishmentNumber(n: number): number {
    return f[n];
};

时间复杂度:O(1)

空间复杂度:O(C),其中 C=1000


Tag: 视频AI Sora 马斯克
歡迎評論
未登錄,
請先 [ 註冊 ] or [ 登錄 ]
(一分鍾即可完成註冊!)
返回首頁     ·   返回[ChatGPT]   ·   返回頂部