mc家族

864

OnjoujiToki

limie

dldl
Kauai

zeng9999jian
NO.1-Finn
yaohy2020
bobo2010
33号花卷

lgvc
zrq071211

11小时前

13小时前
wc这满级人类太牛逼了 https://www.360kuai.com/9ae6b9d30a77bc705?djsource=XsgsZg&sign=360_36e79513&refer_scene=0&scene=25&uid=a1bcbfb5ed12af744b856f1be714892c&tmprtp=expf%3Dcomindexf2043%2C%26reqid%3D7b14dca1-16b3-4943-a89c-a9d685ba2eb1&tj_url=93b4afbeae4ce1fa7&nsid=ef4bc180-c3c1-4484-bbdd-fc57efef4d00（网址）

1天前

1天前

3天前

# include[HTML_REMOVED]

using namespace std;
const int N = 10;
int path[N];//保存序列
int state[N];//数字是否被用过
int n;
void dfs(int u)
{
if(u > n)//数字填完了，输出
{
for(int i = 1; i <= n; i++)//输出方案
cout << path[i] << ” “;
cout << endl;
}

for(int i = 1; i <= n; i++)//空位上可以选择的数字为:1 ~ n
{
if(!state[i])//如果数字 i 没有被用过
{
path[u] = i;//放入空位
state[i] = 1;//数字被用，修改状态
dfs(u + 1);//填下一个位
state[i] = 0;//回溯，取出 i
}
}


}

int main()
{

cin >> n;
dfs(1);
return 0;


}

3天前

class Solution {
public:
bool isScramble(string s1, string s2) {
if (s1.size() != s2.size()) return false;
if (s1 == s2) return true;

    // 统计s1,s2字母是否一致
vector<int> c1(26), c2(26);
for (char c: s1) ++c1[c - 'a'];
for (char c: s2) ++c2[c - 'a'];

for (int i = 0; i < 26; ++i)
if (c1[i] != c2[i]) return false;

// 枚举翻转位置
for (int i = 1; i < s1.size(); ++i){
// 不翻转的情况
if (isScramble(s1.substr(0, i), s2.substr(0, i)) &&
isScramble(s1.substr(i), s2.substr(i))) return true;
// 翻转的情况
if (isScramble(s1.substr(0, i), s2.substr(s2.size() - i)) &&
isScramble(s1.substr(i), s2.substr(0, s1.size() - i))) return true;
}

return false;
}


};

3天前

# include [HTML_REMOVED]

using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f;
int n;
int w[N];
int f[N][2];

int main() {
scanf(“%d”, &n);
for (int i = 1; i <= n; ++i) scanf(“%d”, &w[i]);

f[0][1] = -INF;
for (int i = 1; i <= n; ++i) {
f[i][0] = max(f[i - 1][0], f[i - 1][1] + w[i]);
f[i][1] = max(f[i - 1][1], f[i - 1][0] - w[i]);
}
printf("%d\n", f[n][0]);
return 0;


}

3天前

class Solution {
public:
int rob(vector[HTML_REMOVED]& nums) {
int n = nums.size();
if (nums.empty()) return 0;
if (n == 1) return nums[0];

    vector<int> f(n + 1, 0), g(n + 1, 0);
f[1] = nums[0];
for (int i = 2; i <= n - 1; i ++)
f[i] = max(f[i - 1], f[i - 2] + nums[i - 1]);

g[n - 1] = nums[n - 1];
for (int i = n - 2; i ; i --)
g[i] = max(g[i + 1], g[i + 2] + nums[i]);

return max(f[n -1], g[1]);
}


};

3天前

# include [HTML_REMOVED]

using namespace std;

# define fir(i,a,b) for(int i=a;i<=b;i++)

const int N=1e6+10;
char str[N];
int trie[N][26],n,m,i,j,t,End[N],tot=1;
void insert(char a[])
{
int len=strlen(a),p=1;
fir(i,0,len-1)
{
int ch=a[i]-‘a’;
if (trie[p][ch]==0)
trie[p][ch]=(tot);
p=trie[p][ch];
}
End[p]
;//统计个数
}
int Search(char a[])
{
int len=strlen(a),p=1,ans=0;
fir(i,0,len-1)//把这个字符串所有的前缀都找出来
{
p=trie[p][a[i]-‘a’];
if (p==0)
return ans;
ans+=End[p];
}
return ans;
}
int main()
{
scanf(“%d%d\n”,&n,&t);
fir(i,0,n-1)
{
scanf(“%s\n”,str);
insert(str);
}
while(t–)
{
scanf(“%s\n”,str);
printf(“%d\n”,Search(str));
}
return 0;
}

3天前

class Trie {
Trie son[26] {nullptr};
bool is_tail = false;
public:
/
Initialize your data structure here. /
Trie() {}

/** Inserts a word into the trie. */
void insert(string word) {
Trie *root = this;
for ( const auto& ch : word ) {
if ( !root->son[ch - 'a'] )
root->son[ch - 'a'] = new Trie();
root = root->son[ch - 'a'];
}
root->is_tail = true;
}

/** Returns if the word is in the trie. */
bool search(string word) {
Trie *root = this;
for( const auto& ch : word ) {
if( !root->son[ch - 'a'] )
return false;
root = root->son[ch - 'a'];
}
return root->is_tail;
}

/** Returns if there is any word in the trie that starts with the given prefix. */
bool startsWith(string prefix) {
Trie *root = this;
for( const auto& ch : prefix ) {
if ( !root->son[ch - 'a'] )
return false;
root = root->son[ch - 'a'];
}
return true;
}


};