摘要: 方法一: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 阅读(546) 评论(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 阅读(101) 评论(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 阅读(165) 评论(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 阅读(121) 评论(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 阅读(209) 评论(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 阅读(214) 评论(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 阅读(202) 评论(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 阅读(248) 评论(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 阅读(183) 评论(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 阅读(164) 评论(0) 推荐(0) 编辑