09 2020 档案

摘要:方法一:O(n3) #include <bits/stdc++.h> using namespace std; const int N = 3030; int a[N], b[N], f[N][N]; int n; int main() { scanf("%d",&n); for(int i = 1 阅读全文
posted @ 2020-09-21 10:25 Sexyomaru 阅读(564) 评论(0) 推荐(0)
摘要:class Solution { public int bulbSwitch(int n) { return (int)Math.sqrt(n); // 刚开始灯都是关的,所以按奇数次会打开。比如n = 12; // 会在 第 1,12 2,6 3 ,4 轮被按,所以会被关闭 // 所以序号的因子个 阅读全文
posted @ 2020-09-18 15:19 Sexyomaru 阅读(106) 评论(0) 推荐(0)
摘要:class Solution { private TrieNode root = new TrieNode(); public int minimumLengthEncoding(String[] words) { int res = 0; Arrays.sort(words,(o1,o2)->o2 阅读全文
posted @ 2020-09-15 10:51 Sexyomaru 阅读(174) 评论(0) 推荐(0)
摘要:class Solution { public String removeDuplicateLetters(String s) { int n = s.length(); if(n <= 1) return s; Stack<Character> stack = new Stack<>(); for 阅读全文
posted @ 2020-09-10 16:04 Sexyomaru 阅读(130) 评论(0) 推荐(0)
摘要:解法一: #include <bits/stdc++.h> using namespace std; const int N = 30030; int a[N], f[N], b[N]; int n; int main() { while(cin >> a[n]) n++; int res = 0, 阅读全文
posted @ 2020-09-10 15:03 Sexyomaru 阅读(232) 评论(0) 推荐(0)
摘要:class Solution { int[] pa; int[] pb; public int find(int[] p, int x) { if(p[x] != x) p[x] = find(p,p[x]); return p[x]; } public int maxNumEdgesToRemov 阅读全文
posted @ 2020-09-08 10:01 Sexyomaru 阅读(222) 评论(0) 推荐(0)
摘要:方法一:动态规划 class Solution { public: int minCost(string s, vector<int>& cost) { int n = s.size(),INF = 1e9; vector<vector<int>> f(n,vector<int>(27,INF)); 阅读全文
posted @ 2020-09-07 11:24 Sexyomaru 阅读(220) 评论(0) 推荐(0)
摘要:class Solution { public int countRoutes(int[] pos, int start, int end, int f) { int n = pos.length; int mod = (int)(1e9 + 7); long[][] dp = new long[f 阅读全文
posted @ 2020-09-06 17:15 Sexyomaru 阅读(262) 评论(0) 推荐(0)
摘要:分析:本题可以采用方格取数的代码,证明如下 #include <bits/stdc++.h> using namespace std; const int N = 55; int a[N][N], f[2*N][N][N]; int n, m; int main() { scanf("%d%d",& 阅读全文
posted @ 2020-09-04 16:30 Sexyomaru 阅读(198) 评论(0) 推荐(0)
摘要:#include <bits/stdc++.h> using namespace std; const int N = 15; int w[N][N], f[2*N][N][N]; int n, a, b, c; int main() { scanf("%d",&n); while(cin >> a 阅读全文
posted @ 2020-09-04 11:00 Sexyomaru 阅读(178) 评论(0) 推荐(0)
摘要:#include <bits/stdc++.h> using namespace std; const int N = 100010, M = 1000010; int ne[N]; char s[M], p[N]; int n, m; int main() { cin >> n >> p + 1 阅读全文
posted @ 2020-09-03 11:42 Sexyomaru 阅读(192) 评论(0) 推荐(0)
摘要:#include <bits/stdc++.h> using namespace std; const int N = 100010, M = 3000300; int son[M][2], a[N], idx; int n; void insert(int x) { int p = 0; for( 阅读全文
posted @ 2020-09-03 11:09 Sexyomaru 阅读(207) 评论(0) 推荐(0)
摘要:#include <bits/stdc++.h> using namespace std; const int N = 300000; int son[N][26], cnt[N], idx; int n; char str[N]; void insert(char *str) { int p = 阅读全文
posted @ 2020-09-03 11:08 Sexyomaru 阅读(179) 评论(0) 推荐(0)
摘要:public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 商品数 // 背包大小 int n = sc.nextInt(), m = sc.nextInt( 阅读全文
posted @ 2020-09-02 16:23 Sexyomaru 阅读(184) 评论(0) 推荐(0)
摘要:class Solution { int[] p; int[] s; public int largestIsland(int[][] grid) { if(grid.length == 0) return 0; int n = grid.length, m = grid[0].length; p 阅读全文
posted @ 2020-09-02 11:03 Sexyomaru 阅读(137) 评论(0) 推荐(0)
摘要:方法一:树状数组 class NumArray { int[] nums; int[] bitArr; int n; public NumArray(int[] nums) { n = nums.length; this.nums = nums; bitArr = new int[n+1]; for 阅读全文
posted @ 2020-09-01 15:36 Sexyomaru 阅读(156) 评论(0) 推荐(0)
摘要:class Solution { public List<Integer> findMinHeightTrees(int n, int[][] edges) { List<Integer> res = new ArrayList<>(); if (n == 1) { res.add(0); retu 阅读全文
posted @ 2020-09-01 15:23 Sexyomaru 阅读(136) 评论(0) 推荐(0)