479A - Expression

本文介绍了一个关于数学表达式的编程问题:如何通过合理地插入加号和乘号运算符及括号来使得由三个整数构成的表达式值最大化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Expression
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers abc on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:

  • 1+2*3=7
  • 1*(2+3)=5
  • 1*2*3=6
  • (1+2)*3=9

Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.

It's easy to see that the maximum value that you can obtain is 9.

Your task is: given ab and c print the maximum value that you can get.

Input

The input contains three integers ab and c, each on a single line (1 ≤ a, b, c ≤ 10).

Output

Print the maximum value of the expression that you can obtain.

Sample test(s)
input
1
2
3
output
9
input
2
10
3
output
60
a, b, c= gets.to_i,gets.to_i,gets.to_i
puts [a + b + c, (a + b) * c, a + b * c, a * b + c, a * (b + c), a * b * c].max
PS C:\Users\Administrator\Desktop> # ===== 1. 解决NumPy兼容性问题 ===== PS C:\Users\Administrator\Desktop> function Repair-NumPyCompatibility { >> # 降级NumPy到兼容版本 >> python -m pip uninstall numpy -y >> python -m pip install "numpy==1.26.4" --no-warn-script-location >> >> # 验证安装 >> python -c "import numpy as np; print(f'NumPy版本: {np.__version__}')" >> Write-Host "✅ NumPy兼容性问题已解决" -ForegroundColor Green >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # ===== 2. 修复TorchAudio后端 ===== PS C:\Users\Administrator\Desktop> function Repair-TorchAudioBackend { >> # 安装必要依赖 >> python -m pip install soundfile librosa --no-warn-script-location >> >> # 设置环境变量 >> [Environment]::SetEnvironmentVariable("TORCHAUDIO_USE_BACKEND_DEFAULT", "1", "Machine") >> $env:TORCHAUDIO_USE_BACKEND_DEFAULT = "1" >> >> # 验证修复 >> python -c "import torchaudio; print(torchaudio.get_audio_backend())" >> Write-Host "✅ TorchAudio后端已修复" -ForegroundColor Green >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # ===== 3. 增强仓库索引功能 ===== PS C:\Users\Administrator\Desktop> function Update-EnhancedRepositoryIndex { >> param( >> [string]$RepositoryPath = "E:\ai_pip_repository" >> ) >> >> $downloadedDir = Join-Path $RepositoryPath "downloaded_packages" >> >> # 创建JSON索引 >> $jsonIndex = @{ >> packages = @() >> last_updated = [DateTime]::Now.ToString("o") >> } >> >> # 收集包信息 >> Get-ChildItem $downloadedDir -File | ForEach-Object { >> $packageName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name) >> $version = if ($packageName -match '(.+)-(\d+\.\d+\.\d+)') { >> $matches[2] >> } else { "unknown" } >> >> $jsonIndex.packages += @{ >> name = $matches[1] >> version = $version >> size = $_.Length >> sha256 = (Get-FileHash $_.FullName -Algorithm SHA256).Hash >> last_modified = $_.LastWriteTime.ToString("o") >> } >> } >> >> # 写入JSON文件 >> $jsonIndex | ConvertTo-Json -Depth 3 | Out-File (Join-Path $RepositoryPath "index.json") -Encoding UTF8 >> Write-Host "✅ 增强仓库索引已更新" -ForegroundColor Green >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # ===== 执行修复 ===== PS C:\Users\Administrator\Desktop> Repair-NumPyCompatibility Found existing installation: numpy 2.2.6 Uninstalling numpy-2.2.6: Successfully uninstalled numpy-2.2.6 WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting numpy==1.26.4 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/19/77/538f202862b9183f54108557bfda67e17603fc560c384559e769321c9d92/numpy-1.26.4-cp310-cp310-win_amd64.whl (15.8 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.8/15.8 MB 66.2 MB/s 0:00:00 WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Installing collected packages: numpy WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Successfully installed numpy-1.26.4 NumPy版本: 1.26.4 ✅ NumPy兼容性问题已解决 PS C:\Users\Administrator\Desktop> Repair-TorchAudioBackend WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting soundfile Downloading https://pypi.tuna.tsinghua.edu.cn/packages/14/e9/6b761de83277f2f02ded7e7ea6f07828ec78e4b229b80e4ca55dd205b9dc/soundfile-0.13.1-py2.py3-none-win_amd64.whl (1.0 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 9.7 MB/s 0:00:00 Collecting librosa Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b5/ba/c63c5786dfee4c3417094c4b00966e61e4a63efecee22cb7b4c0387dda83/librosa-0.11.0-py3-none-any.whl (260 kB) Collecting cffi>=1.0 (from soundfile) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d1/b6/0b0f5ab93b0df4acc49cae758c81fe4e5ef26c3ae2e10cc69249dfd8b3ab/cffi-1.17.1-cp310-cp310-win_amd64.whl (181 kB) Requirement already satisfied: numpy in e:\python310\lib\site-packages (from soundfile) (1.26.4) Collecting audioread>=2.1.9 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/57/8d/30aa32745af16af0a9a650115fbe81bde7c610ed5c21b381fca0196f3a7f/audioread-3.0.1-py3-none-any.whl (23 kB) Collecting numba>=0.51.0 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b1/c6/c2fb11e50482cb310afae87a997707f6c7d8a48967b9696271347441f650/numba-0.61.2-cp310-cp310-win_amd64.whl (2.8 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.8/2.8 MB 32.5 MB/s 0:00:00 Collecting scipy>=1.6.0 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d1/84/55bc4881973d3f79b479a5a2e2df61c8c9a04fcb986a213ac9c02cfb659b/scipy-1.15.3-cp310-cp310-win_amd64.whl (41.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.3/41.3 MB 84.7 MB/s 0:00:00 Collecting scikit-learn>=1.1.0 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/12/7b/e1ae4b7e1dd85c4ca2694ff9cc4a9690970fd6150d81b975e6c5c6f8ee7c/scikit_learn-1.7.1-cp310-cp310-win_amd64.whl (8.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.9/8.9 MB 78.5 MB/s 0:00:00 Collecting joblib>=1.0 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7d/4f/1195bbac8e0c2acc5f740661631d8d750dc38d4a32b23ee5df3cde6f4e0d/joblib-1.5.1-py3-none-any.whl (307 kB) Collecting decorator>=4.3.0 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4e/8c/f3147f5c4b73e7550fe5f9352eaa956ae838d5c51eb58e7a25b9f3e2643b/decorator-5.2.1-py3-none-any.whl (9.2 kB) Collecting pooch>=1.1 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a8/87/77cc11c7a9ea9fd05503def69e3d18605852cd0d4b0d3b8f15bbeb3ef1d1/pooch-1.8.2-py3-none-any.whl (64 kB) Collecting soxr>=0.3.2 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ad/64/86082b6372e5ff807dfa79b857da9f50e94e155706000daa43fdc3b59851/soxr-0.5.0.post1-cp310-cp310-win_amd64.whl (166 kB) Requirement already satisfied: typing_extensions>=4.1.1 in e:\python310\lib\site-packages (from librosa) (4.14.1) Collecting lazy_loader>=0.1 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/83/60/d497a310bde3f01cb805196ac61b7ad6dc5dcf8dce66634dc34364b20b4f/lazy_loader-0.4-py3-none-any.whl (12 kB) Collecting msgpack>=1.0 (from librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7d/18/73dfa3e9d5d7450d39debde5b0d848139f7de23bd637a4506e36c9800fd6/msgpack-1.1.1-cp310-cp310-win_amd64.whl (71 kB) Collecting pycparser (from cffi>=1.0->soundfile) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/13/a3/a812df4e2dd5696d1f351d58b8fe16a405b234ad2886a0dab9183fb78109/pycparser-2.22-py3-none-any.whl (117 kB) Collecting packaging (from lazy_loader>=0.1->librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl (66 kB) Collecting llvmlite<0.45,>=0.44.0dev0 (from numba>=0.51.0->librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/69/07/35e7c594b021ecb1938540f5bce543ddd8713cff97f71d81f021221edc1b/llvmlite-0.44.0-cp310-cp310-win_amd64.whl (30.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 30.3/30.3 MB 87.7 MB/s 0:00:00 Collecting platformdirs>=2.5.0 (from pooch>=1.1->librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fe/39/979e8e21520d4e47a0bbe349e2713c0aac6f3d853d0e5b34d76206c439aa/platformdirs-4.3.8-py3-none-any.whl (18 kB) Requirement already satisfied: requests>=2.19.0 in e:\python310\lib\site-packages (from pooch>=1.1->librosa) (2.32.5) Requirement already satisfied: charset_normalizer<4,>=2 in e:\python310\lib\site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (3.4.3) Requirement already satisfied: idna<4,>=2.5 in e:\python310\lib\site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (3.10) Requirement already satisfied: urllib3<3,>=1.21.1 in e:\python310\lib\site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (2.5.0) Requirement already satisfied: certifi>=2017.4.17 in e:\python310\lib\site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (2025.8.3) Collecting threadpoolctl>=3.1.0 (from scikit-learn>=1.1.0->librosa) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/32/d5/f9a850d79b0851d1d4ef6456097579a9005b31fea68726a4ae5f2d82ddd9/threadpoolctl-3.6.0-py3-none-any.whl (18 kB) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Installing collected packages: threadpoolctl, soxr, scipy, pycparser, platformdirs, packaging, msgpack, llvmlite, joblib, decorator, audioread, scikit-learn, pooch, numba, lazy_loader, cffi, soundfile, librosa WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Successfully installed audioread-3.0.1 cffi-1.17.1 decorator-5.2.1 joblib-1.5.1 lazy_loader-0.4 librosa-0.11.0 llvmlite-0.44.0 msgpack-1.1.1 numba-0.61.2 packaging-25.0 platformdirs-4.3.8 pooch-1.8.2 pycparser-2.22 scikit-learn-1.7.1 scipy-1.15.3 soundfile-0.13.1 soxr-0.5.0.post1 threadpoolctl-3.6.0 soundfile ✅ TorchAudio后端已修复 PS C:\Users\Administrator\Desktop> Update-EnhancedRepositoryIndex ✅ 增强仓库索引已更新 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # ===== 最终验证 ===== PS C:\Users\Administrator\Desktop> python -c "import torch, torchvision, torchaudio, numpy as np; print(f'PyTorch: {torch.__version__}\nTorchVision: {torchvision.__version__}\nTorchAudio: {torchaudio.__version__}\nNumPy: {np.__version__}\nAudio Backend: {torchaudio.get_audio_backend()}')" PyTorch: 2.0.0+cpu TorchVision: 0.15.1+cpu TorchAudio: 2.0.1+cpu NumPy: 1.26.4 Audio Backend: soundfile PS C:\Users\Administrator\Desktop> # 验证所有组件 PS C:\Users\Administrator\Desktop> python -c "import torch, torchvision, torchaudio, numpy as np; print(f'PyTorch: {torch.__version__}\nTorchVision: {torchvision.__version__}\nTorchAudio: {torchaudio.__version__}\nNumPy: {np.__version__}\nAudio Backend: {torchaudio.get_audio_backend()}')" PyTorch: 2.0.0+cpu TorchVision: 0.15.1+cpu TorchAudio: 2.0.1+cpu NumPy: 1.26.4 Audio Backend: soundfile PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 检查仓库索引 PS C:\Users\Administrator\Desktop> Get-Content "E:\ai_pip_repository\index.json" | ConvertFrom-Json | Select-Object last_updated, @{Name="PackageCount"; Expression={$_.packages.Count}} last_updated PackageCount ------------ ------------ 2025-08-22T01:10:38.7143409+08:00 17 PS C:\Users\Administrator\Desktop>
最新发布
08-23
(fealpy_env) py@py:~$ pip3 install PyMUMPS Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting PyMUMPS Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8d/36/75ff7ce99ff1f65132af5a310c10eeb6f80537ad352570a39f1c1eb239b7/pymumps-0.3.3.tar.gz (8.2 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Collecting mpi4py (from PyMUMPS) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/85/22/4d9a9290010d4b95d3991ac383b2b7763ecebccafe366cb64f4abf479c41/mpi4py-4.1.0-cp310-cp310-manylinux1_x86_64.manylinux_2_5_x86_64.whl (1.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.4/1.4 MB 10.7 MB/s eta 0:00:00 Building wheels for collected packages: PyMUMPS Building wheel for PyMUMPS (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for PyMUMPS (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [40 lines of output] /tmp/pip-build-env-d5nmvfu3/overlay/lib/python3.10/site-packages/setuptools/dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: BSD License See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! self._finalize_license_expression() running bdist_wheel running build running build_py creating build/lib.linux-x86_64-cpython-310/mumps copying mumps/__init__.py -> build/lib.linux-x86_64-cpython-310/mumps running build_ext warning: mumps/_dmumps.pyx:62:23: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:62:29: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:62:38: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:62:51: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:63:23: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:63:37: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:63:48: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:67:27: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:67:37: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:68:28: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. warning: mumps/_dmumps.pyx:68:40: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line. Compiling mumps/_dmumps.pyx because it changed. [1/1] Cythonizing mumps/_dmumps.pyx building 'mumps._dmumps' extension creating build/temp.linux-x86_64-cpython-310/mumps x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/home/py/fealpy_env/include -I/usr/include/python3.10 -c mumps/_dmumps.c -o build/temp.linux-x86_64-cpython-310/mumps/_dmumps.o mumps/_dmumps.c:1136:10: fatal error: dmumps_c.h: No such file or directory 1136 | #include "dmumps_c.h" | ^~~~~~~~~~~~ compilation terminated. error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for PyMUMPS Failed to build PyMUMPS ERROR: Failed to build installable wheels for some pyproject.toml based projects (PyMUMPS) (fealpy_env) py@py:~$
07-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值