File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -371,6 +371,45 @@ impl Solution {
371
371
}
372
372
}
373
373
```
374
+ ### C:
375
+ ``` c
376
+ #define MOD 1000000007
377
+ int numDistinct(char * s, char * t)
378
+ {
379
+ //dp[ i] [ j ] : t前i个字符,s前j个字符,s子序列中t出现的个数
380
+ int ** dp = malloc(sizeof(int * ) * (strlen(t) + 1));
381
+ for (int i = 0; i <= strlen(t); i++)
382
+ {
383
+ dp[ i] = malloc(sizeof(int) * (strlen(s) + 1));
384
+ }
385
+
386
+ // 初始化
387
+ for (int i = 0 ; i <= strlen(t); i++)
388
+ {
389
+ dp[i][0] = 0;
390
+ }
391
+ for (int j = 0; j <= strlen(s); j++)
392
+ {
393
+ dp[0][j] = 1;
394
+ }
374
395
396
+ // 遍历
397
+ for (int i = 1; i <= strlen(t); i++)
398
+ {
399
+ for (int j = 1; j <= strlen(s); j++)
400
+ {
401
+ if (s[j - 1] == t[i - 1])
402
+ {
403
+ dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
404
+ }
405
+ else
406
+ {
407
+ dp[i][j] = dp[i][j - 1];
408
+ }
409
+ }
410
+ }
411
+ return dp[strlen(t)][strlen(s)] % MOD;
412
+ }
413
+ ```
375
414
376
415
You can’t perform that action at this time.
0 commit comments