解题思路:深搜一波,超时哈哈91%
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
private static int vu=0;
private static int[] a;
private static int[][] v=new int[1004][2];
private static int mac=0;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n=input.nextInt(),s=input.nextInt(),c=input.nextInt(),b=input.nextInt();
a=new int[]{c,-b};
for (int i = 1; i <1000000; i++) {
mac=i;
dfs(i,1,n,s);
}
System.out.println(vu%100000007);
}
private static void dfs(int mun, int count,int n, int s) {
if(mac==s&&count==n){
vu++;
return;
}
else if(count==n){
return;
}
else{
for (int i = 0; i <2; i++) {
if(v[count][i]==0){
v[count][i]=1;
mac+=mun+a[i];
dfs(mun+a[i],count+1,n,s);
mac-=mun+a[i];
v[count][i]=0;
}
}
}
}
}
0.0分
4 人评分
C语言训练-自守数问题 (C语言代码) long long浏览:1061 |
母牛的故事 (C语言代码)浏览:1298 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:928 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:525 |
简单的a+b (C语言代码)浏览:704 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:567 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:1078 |
【偶数求和】 (C语言代码)浏览:640 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:504 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:562 |