class Solution {
public:intnumDecodings(string s){int n = s.size();
vector<int>f(n +1);
s =' '+ s;//处理边界
f[0]=1;for(int i =1; i <= n; i ++){
f[i]=0;if(s[i]!='0') f[i]+= f[i -1];if(i >1){int t =(s[i -1]-'0')*10+(s[i]-'0');if(t >=10&& t <=26)
f[i]+= f[i -2];}}return f[n];}};
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode*reverseBetween(ListNode* head,int m,int n){if(m == n)return head;if(!head)return0;
ListNode* dummy = new ListNode(-1);
dummy->next = head;
ListNode* a = dummy;for(int i =0; i < m -1; i ++) a = a->next;
ListNode* b = a;
b = b->next;
ListNode* c = b->next;for(int i =0; i < n - m; i ++){
ListNode* next = c->next;
c->next = b;
b = c;
c = next;}
ListNode* an = a->next;
a->next = b;
an->next = c;return dummy->next;}};
class Solution {
public:
vector<string> res;
vector<string>restoreIpAddresses(string s){
string path;dfs(s,0,0, path);return res;}voiddfs(string &s,int u,int k, string path)//u 枚举到哪一位 k枚举到的地址位数{if(u == s.size()){if(k ==4){
res.push_back(path.substr(1));//剪去最前面的点}return;}if(k >4)return;//剪枝if(s[u]=='0')dfs(s, u +1, k +1, path +".0");else{for(int i = u, t =0; i < s.size(); i ++){
t = t *10+ s[i]-'0';if(t <256)dfs(s, i +1, k +1, path +"."+to_string(t));elsebreak;}}}};
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> res;
vector<int>inorderTraversal(TreeNode* root){dfs(root);return res;}voiddfs(TreeNode* root){if(!root)return;if(root->left)dfs(root->left);
res.push_back(root->val);if(root->right)dfs(root->right);}};
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int>inorderTraversal(TreeNode* root){
vector<int> res;
stack<TreeNode*> stk;
TreeNode* now = root;while(now ||!stk.empty()){while(now){
stk.push(now);
now = now->left;}if(!stk.empty()){
now = stk.top();
stk.pop();
res.push_back(now->val);
now = now->right;}}return res;}};
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<TreeNode*>generateTrees(int n){if(!n)return vector<TreeNode*>();returndfs(1, n);//生成所有由1...n为节点所组成的二叉搜索树}
vector<TreeNode*>dfs(int l,int r){
vector<TreeNode*> res;if(l > r){
res.push_back(NULL);return res;}for(int i = l; i <= r; i ++){//i为根节点auto left =dfs(l, i -1), right =dfs(i +1, r);for(auto< : left)for(auto&rt : right){auto root = new TreeNode(i);
root->left = lt, root->right = rt;
res.push_back(root);}}return res;}};
class Solution {
public:intnumTrees(int n){
vector<int>f(n +1);
f[0]=1;for(int i =1; i <= n; i ++){
f[i]=0;for(int j =1; j <= i; j ++)
f[i]+= f[j -1]* f[i - j];}return f[n];}};
class Solution {
public:
bool isInterleave(string s1, string s2, string s3){int n = s1.size(), m = s2.size(), k = s3.size();if(n + m != k)return false;
vector<vector<int>>f(n +1, vector<int>(m +1));
f[0][0]=1;for(int i =1; i <= n; i ++)
f[i][0]= f[i -1][0]&& s1[i -1]== s3[i -1];for(int j =1; j <= m; j ++)
f[0][j]= f[0][j -1]&& s2[j -1]== s3[j -1];for(int i =1; i <= n; i ++)for(int j =1; j <= m; j ++){
f[i][j]=0;if(s1[i -1]== s3[i + j -1])
f[i][j]|= f[i -1][j];if(s2[j -1]== s3[i + j -1])
f[i][j]|= f[i][j -1];}return f[n][m];}};