十七

leetcode53. 最大子数组和

分析用f[i]来表示数组中第i个位置的最大数组和,那么计算f[i]的时候就需要从f[i-1]转移过来,转移方程为f[i]=max(f[i-1]+nums[i],nums[i]),由于只与f[i]和f[i-1]有关,可以用pre来表示i-1,ans来表示i。class Solution {public

十七 Published on 2022-02-19

leetcode51. N 皇后

class Solution { char g[10][10]; bool col[20],dg[20],udg[20]; vector<vector<string>> res;//保存答案 vector<string> str;//用于保

十七 Published on 2022-02-19

leetcode50. Pow(x, n)

分析使用快速幂做法class Solution {public: double myPow(double x, int n) { double ans=1.0; if(x==0)return 0.0; long b=n; if(b&lt

十七 Published on 2022-02-18
十七 Published on 2022-02-18

leetcode49. 字母异位词分组

分析string排序后的值相同的,可以使用字符串哈希将对应的字符串加进vector中,最后遍历哈希表,得到答案class Solution {public: vector<vector<string>> groupAnagrams(vector<string&gt

十七 Published on 2022-02-18
十七 Published on 2022-02-18

acwing9. 分组背包问题

分析01背包是每个物品只能选一次,这里是每组只能选一个,我们可以遍历s[i]次。选出每组中的最大值即可。#include<iostream>using namespace std;const int N=110;int v[N][N],w[N][N],s[N],f[N];int n,m;

十七 Published on 2022-02-18
Previous Next